Creating, Viewing, and Editing Text Files in Linux | Mostafa Mahmoud | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Creating, Viewing, and Editing Text Files in Linux

teacher avatar Mostafa Mahmoud, Data Scientist/ML Engineer/Linux Expert

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

6 Lessons (36m)
    • 1. 00 Class Overview

      1:04
    • 2. The touch command

      2:43
    • 3. 01 Redirecting Output to a File or Program

      13:26
    • 4. 02 Editing Text Files from the Shell Prompt

      7:30
    • 5. 03 Editing Text Files with a Graphical Editor

      6:45
    • 6. Exercise 5

      4:13
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

11

Students

--

Projects

About This Class

RHEL 8 / CentOS 8 Linux Administration - RHCSA 8 - Class Four

Creating, Viewing, and Editing Text Files in Linux

Hi, I'm Mustafa Mahmoud. A Senior Linux Administrator and Online Instructor. I have been working as Linux System Administrator for more than ten years, currently devoted to teaching. I like to share my knowledge with others and help them advance in their careers.

Students testimonials - See what others say!

  • Siddharth Kumar: I really loved the course content and the way all details have been explained by the trainer, it will certainly help me or anyone else to improve their Linux administration skills.
  • Eric Voigt: Excellent overview of the basic skills, well organized and taught.
  • Suman Mandal: This course was useful to me. I have learned many things that were not clear to me. Thank you.

What you should know before starting

class content:

  • Describing the technical terms of standard input, standard output, and standard error.

  • Using redirection characters to control output to files.

  • Using piping to control output to other programs.

  • Creating new files and edit existing text files from the shell prompt.

  • Navigating within an editor to effectively accomplish editing tasks.

  • Using the Vim editor in the basic editing tasks.

  • Editing text files with gedit.

  • Copying text between graphical windows.

What's next?

RHEL 8 / CentOS 8 Linux System Administration - RHCSA 8 - Class Five

Meet Your Teacher

Teacher Profile Image

Mostafa Mahmoud

Data Scientist/ML Engineer/Linux Expert

Teacher

Hello, I'm Mostafa. A data scientist, ml engineer, and Linux expert. I worked for ten years as a Linux systems administrator at Express, then I had the opportunity to turn to data science. Because of my passion for this field and my keen attention to detail, I got my Udacity certifications to work as a data scientist and machine learning engineer. The most recent projects I worked on were Finding Donors for CharityML, a full exploratory and explanatory analytics work project for Ford Go Bike company trips data, and creating a logistic regression to predict absenteeism. I'm working on improving my skills and looking for job opportunities that will help me in this direction.

Skills: Python, SQL, Linux
Applications: Jupyter Notebook, Weka, Excel, Pycharm,... See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. 00 Class Overview: RHEL 8 and CentOS 8 Linux system administration RHCSA class four overview. In this class, you will learn creating, viewing, and editing text files in Linux, which will include, describing the technical terms, standard input, standard output, and standard error, using the redirection characters to control output to files. Using piping to control output to other programs. Creating new files and editing existing text files from the shell prompt. Navigating within an editor to effectively accomplish editing tasks. Using the editor in The basic editing tasks. Editing text files with gedit, Copying text between graphical windows. 2. The touch command: The touch command is a standard program for Linux operating systems that is used to create, change and modify timestamps of a file. Let's take some examples of using the touch command. To create an empty file test you can use the command and to check to change or update the last access and modification time of the file data. You can use the -a option. For example, to check Here, I used the -u option to show last access time instead of last modification time. Using the -a option, sets the current time and date on a file. Here, if the data file doesn't exist, it will create a new empty file data. To avoid creating a new file, you can use the -c option. For example, to check. This command will not create the file text if it doesn't exist. If you like to change only the modification time of the file test, then you can use that -m option, for example. To check Note, it will only update the last modification time of the test file and the access time will remain as it is. The touch command can also create any number of files simultaneously, for example, to create three new empty files named file one, file two and file three. You can use the command to check. Thank thanks for viewing. 3. 01 Redirecting Output to a File or Program: Redirecting output to a file or program. After completing this lecture, you should be able to describe the technical terms standard input, standard output, and standard error. Use redirection characters to control output to files. And use piping to control output to other programs. A process structure is constructed with numbered channels called (file descriptors) to manage open files. Processes connect to files to reach data content or devices these files represent. Processes are created with default connections for channels 0, 1, and 2, known as standard input, standard output, and standard error. Processes use channel three and above to connect to other files. Channel redirection replaces default channel destinations with file names representing either output files or devices. Using redirection, process output and error messages can be captured as file contents, sent to a device, or discarded. Redirecting stdout suppresses process output from appearing on the terminal. As seen in this example, redirecting only standard output doesn't suppress standard error messages from displaying on the terminal. The special file /dev/null quietly discards channel output redirected to it. As in this example, when redirecting the standard error. Note that, the previous commands will overwrite or append to an existing file or create a new file if the file is not existing. The order of redirection is important to avoid unexpected command behavior. Using the command 2>&1 2>&1 Sends the standard error (stderr) to the same place as the standard output (stdout). For this to work, standard out (stdout) needs to be redirected first before adding standard error (stderr) to standard output (stdout). Although using the command &>> is an alternate way to append both standard out and standard error to a file, using the command 2>&1 2>&1 is the method needed to send both standard output and standard error through a pipe. Let's take some examples of output redirection. Many routine administration tasks are simplified by using redirection, use the previous table to assist while considering the coming examples. The first example is for saving a timestamp for later reference. Here, we will use the date command followed by the redirection operator. Followed by the path, followed by the filename. For example, timestamp. We can check using the cat command. Another example to copy the last 100 lines from a log file to another file. First, I will need to switch to root user using the su command followed by the redirection operator. Followed by the file name To check. You can press Tab for auto completion. To concatenate three files into one file, first, I will need to create three files using the touch command in the /tmp directory. Then I will add some data in each file using the echo command and redirection operator. Then you can check the data entered in the files using the cat command. Now to concatenate the three files into one file. To check. For listing the home directories hidden and regular file names into a file first, you will need to ensure that you are in the home directory, you can check the tilde sign and if you are in a different one you can use the command cd~, cd~, To switch to the home directory now to list the home directories hidden and regular file names into a file. And to check. Another example, to append the output of the date command to the existing file timestamp using the append operator. For the coming example, we will first need to switch to normal user, you can use Ctrl+D In this example, errors are generated since normal users are denied access to system directories. To redirect errors to a file while viewing normal command output on the terminal. I used the command 2> followed by the error file. To check. And to save process output and error messages to separate files, we will use this command. And to check. To ignore and discard error messages. We can redirect it to /dev/null /dev/null To store output and generated errors together, we can use the command &> &> like in this example. And to append output and generated errors to an existing file. To check. Or you can use, &>> followed by the file name. Constructing pipelines. Redirection controls channel output to or from files, while piping sends channel output to another process. Let's take some examples. To Paginate a command long output by piping it to less command. type less less is a program that allows backwards and forward movement in the file. You can do this using page down and page up or the space bar. Also, it doesn't have to read the entire input file before starting so with large input files, it starts up faster than text editors. You can press q to quit. In this example, we used the -l option for long listing format. Another example to count the number of lines in output or listing, type. The -l option is used with the wc command to print the newline counts. Now to check Process, input, and output piping with tee command. The tee command displays or redirects the intermediate result normally suppressed due to piping. Let's take some examples. In this example, the ls listing is viewed on a terminal while simultaneously being stored in a file. I hope this has been informative for you, and I'd like to thank you for viewing. 4. 02 Editing Text Files from the Shell Prompt: Editing text files from the shell prompt After completing this lecture, you should be able to create new files and edit existing text files from the shell prompt. Navigate within an editor to effectively accomplish editing tasks. Use the Vim editor in the basic editing tasks. A key design principle of Linux is that information is stored in text-based files. Text files include both flat files with rows of similar information, such as configuration files in /etc directory, and Extensible Markup Language (XML) files, which define data structure through text tags, seen in the application configuration files throughout both /etc and /usr directories. The advantage of text files is that they can be moved or shared between systems without requiring conversion, and can be viewed and edited using any simple text editor. Vim is an improved version of the vi editor distributed with Linux and UNIX systems. It is the most popular and classic text editor in the Linux family. Highly configurable and efficient for practiced users, including features as split screen editing, color formatting, and highlighting for editing text. When you open them it starts in command mode used for navigation cut and paste, and other text manipulation, you can enter each of the other modes with a single character keystroke to access a specific editing functionality. An 'I' keystroke enters insert mode, where all text typed becomes file content. Pressing Esc returns to command mode. A ‘v’ keystroke enters visual mode, where multiple characters may be selected for text manipulation. You can use 'v' for multiline, and Ctrl+V for block selection. The same keystroke used to enter visual mode, uppercase V, lowercase v or Ctrl+V is also used to exit. The colon ':' keystroke begins extended command mode for tasks like writing the file to save it, and quitting the VIM editor, by following it with characters like 'q' or 'wq' or others according to what you want to do. For example, ':q' will exit without saving. And ':wq' will save and exit. Let's take a look at the basic VIM workflow. The basic VIM workflow represents the minimum keystrokes every VIM user must learn to accomplish any editing task. To open a file with VIM, type 'vim' followed by the 'filename'. It's important to not forget the space between 'vim' and the 'filename'. Then press Enter. After opening the file, if the file you opened contains data, you can Arrow keys to position the cursor. You can press the 'I' key to enter the insert mode. Now you can add new text to the file or edit the existing. Press 'Esc' to return to command mode. You can press 'U' to undo mistaken edits on the current line. And you can press Ctrl+R to redo. Also, you can press 'X' to delete a selection of text. To save or exit, choose one of the following to write or discard, file edits. You can enter ':w' followed by Enter to save the file and remain in command mode for more editing. Or ':wq' followed by Enter to write the file and quit VIM. Or ':q!' followed by Enter to quit VIM, but discard all file changes since the last write. In VIM, copy and paste is known as the Yank and Put, using command characters 'Y' and 'P'. Begin by positioning the cursor on the first character to be selected. Then enter visual mode by pressing 'V'. Use Arrow keys to expand the visual selection. When ready press 'Y' to yank the selection into memory. Position the cursor at the new location. Then press 'P' to put the selection at the cursor. Now, to quit VIM and discard the changes, press 'Esc' to enter the command mode. Then type ':q!' ':q!' and press Enter. Beware that, VIM requires practice to become efficient. It is recommended to continue learning new keystrokes to extend VIM's usefulness. For those curious how extensive this can be, perform an Internet search for VIM tips. Also, you can use the Vimtutor to learn your first VIM commands, which is a 30-minute tutorial that teaches you the most basic VIM functionality in eight easy exercises, while you can learn everything about VIM in just half an hour. The tutor is designed to describe enough of the commands that you will be able to easily use VIM as an all purpose editor. You can start this program from the shell or command-line by entering the vimtutor command. This will make a copy of the tutor file so that you can edit it without the risk of damaging the original. There are few translated versions of the tutor, to find out if yours is available, use the two-letter language code. For example, for French, this would be 'vimtutor fr' 'vimtutor fr' If installed on the system. I hope this has been informative for you, and I would like to thank you for viewing. 5. 03 Editing Text Files with a Graphical Editor: Editing Text Files with a Graphical Editor. After completing this lecture, you should be able to: Edit text files with gedit. Copy text between graphical windows. The gedit application is a full-featured text editor for the GNOME desktop environment. You can launch gedit by selecting activities. Activities > Show Applications > All > Text Editor. Activities > Show Applications > All > Text Editor. Text Editor. Also, like other graphical applications, gedit can be started without navigating the menu. Press Alt+F2 Open, the Enter a Command dialog box, then type gedit and press enter. you can perform many file management tasks using gedits menu hits first enter some data in the document to create a new file in gedit Click the blank paper toolbar icon which will create a new document in a separate tab within the same window. Or from the Text Editor menu. Select New Document. And to open a new document in a separate window, you can press the Text Editor button. and choose New Window Or you can press Ctrl+N which will also create a new document in a separate window. To save a file you can click the save button. Then type the new file name or confirm with the current by clicking the Save button. Or from this button. Select save as or save all. Also, you can easily press Ctrl+S to save the file. To open an existing file, click the open toolbar button, then click on the Other Documents button. The open files dialog window will display from which users can locate and select the file to open. Multiple files may be opened simultaneously, each with a unique tab under the menu bar. Tabs will display the file name after being saved the first time. Copying text between graphical windows. Text can be copied between documents, text windows, and command windows in the graphical environment. The selected text is duplicated using copy and paste or moved using cut and paste. Weather cut or copied The text is held in memory for pasting into another location. To select text, click and hold the left mouse button before the first character desired. Drag the mouse over and down until all required text is in a single highlighted selection. Then release the left button, don't click again with the left button as that deselect is the text. To paste the selection, multiple methods can accomplish the same result, in the first method, click the right mouse button anywhere on the text area just selected. From the resulting context menu, select either cut or copy. Move the mouse to the window or document where the text is to be placed. Click the left mouse button to position where the text should go. Click the right mouse button again, now choosing paste. A Shorter mouse technique is to. First, select the text. Hover the mouse, over the destination Window, and click the center mouse button just once to paste the text at the cursor. Note that, this method can only copy not cut, and the original text remains selected and can be deleted, as with other methods, the text remains a memory and can be repeatedly pasted. The keyboard shortcut method can also be used in graphical applications. First, select the text. Use Ctrl+X to cut or Ctrl+C to copy the text. Click the location where the text is to be placed to position the cursor. Then click Ctrl+V to paste. Note that, Ctrl+C and Ctrl+V will not copy and paste within a terminal window, and that Ctrl+C will actually terminate the currently running process within a terminal window. To copy and paste within a terminal window, you can use Ctrl+Shift+C to copy and Ctrl+Shift+V to paste. I hope this has been informative for you and I'd like to thank you for viewing. 6. Exercise 5: So satisfied explanation. To save your home directory content, to list file in the directory using the output v direction. As I've already present in my home directory. I will direct the type that command to check two times ten to the list file using the command to copy the last 20 lines from slash bore log messages by using the tail command and the output v direction. First I will need to switch to the root user. The command. To check. Switch back to the normal user press control 5152 and add some data in each file. To concatenate Phi 152 using cat command and direction. To check to ignore the error message that will appear when you try as a normal user to change the buzzword of another user using redirection operator. A list of all the files in the sludge ETC. Directory, and save the output Tuesday HTML files file using the D command to check for viewing.