Lesson 2 - Exploring Linux Command-Line Tools - Part 2 - 2-Đã M Khóa
Lesson 2 - Exploring Linux Command-Line Tools - Part 2 - 2-Đã M Khóa
tools (Cont.)
I. Log in to the system
1. Find the line in the /etc/passwd file for user name that start with student.
2. Find all lines in the /etc/passwd file that begin with the letter st.
3. Find all lines in /etc/passwd that contain a digit 0-9.
4. Repeat the search in the previous instruction, but this time display only the number
of lines that contain the pattern.
5. Use the ps and grep commands to display the processes initiated by users other
than yourself.
6. Create a file with the content as follow, name it anything you want:
Fred apples 20
Susy oranges 5
Mark watermellons 12
Robert pears 4
Terry oranges 9
Lisa peaches 7
Susy oranges 12
Mark grapes 39
Anne mangoes 7
Greg pineapples 3
Oliver rockmellons 2
Betty limes 14
11. Using the cat command and redirection, create a file called junk containing a
few lines of text. Use <ctrl-d> at the beginning of a new line when you have
finished entering text and want to return the shell $ prompt.
12. Append more lines of text to the file you have created using the cat command
and redirection.
13. Using the ls command, list the files in your current directory. Make a note of the
number of files. _____
Log int to the CentOS system with the user name and password provided:
student/lpic1@123
1. Find all lines in the /etc/passwd file for user names that start with student.
2. Find all lines in the /etc/passwd file that begin with the letter st.
4. Repeat the search in the previous instruction, but this time display only the
number of lines that contain the pattern.
5. Use the ps and grep commands to display the processes initiated by users
other than yourself.
6. Create a file with the content as follow, name it anything you want:
Fred apples 20
Susy oranges 5
Mark watermellons 12
Robert pears 4
Terry oranges 9
Lisa peaches 7
Susy oranges 12
Mark grapes 39
Anne mangoes 7
Greg pineapples 3
Oliver rockmellons 2
Betty limes 14
9. Find all the people with the name begin with the letter from A to L
$ grep ‘^[A-L]’ <your file>
11. Using the cat command and redirection, create a file called junk containing a
few lines of text. Use <ctrl-d> at the beginning of a new line when you have
finished entering text and want to return the shell $ prompt.
12. Append more lines of text to the file you have created using the cat command
and redirection.
13. Using the ls command, list the files in your current directory. Make a note of
the number of files. _____
• $ ls
14. List the files in your current directory, but this time redirect the output to the
file temp.
• $ ls > temp
15. Use the appropriate command to count the number of words in the temp file.
Is this the same count as in instruction 11? __________ If not, why
not?__________ Display the contents of temp. Remove the file.
• $ wc -w temp
• $ cat temp
• $ rm temp
• $ ls | wc -w
17. Display all the content of the file you created at excercise 6, but find and
replace all the oranges to apples
$ cat <your file> | sed ‘s/oranges/apples/g’
18. Using xargs and $() to generate the ls -l command to all the file inside your
home directory that have string te in the file name
$ ls | grep te | xargs ls -l
$ ls -l $(ls | grep te)