Linux Commands Dubai

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

BITS PILANI DUBAI CAMPUS

CS F111 Computer Programming


Lab #2: Unix Commands Cheat Sheet and Practice Exercises

# Command Action Accomplished


Display the complete path of the directory you are currently
1 pwd
positioned in
list
2 ls List the contents of the directory; often used with the –a
(all) and –l (long listing) options
3 mkdir <dir_name> Create a subdirectory under the current working directory
Change directory to the one whose location is specified, or
4 cd
to home directory, if nothing is mentioned
5 clear Clear screen
6 date Displays the current date and time
who Displays the list of all users logged in
7
who am i Displays your own username and details
8 cal Calendar – also takes arguments
Displays the user manual entry for the command
9 man <command>
mentioned
If used with filename(s), displays the contents of the file(s);
10 cat
also used to create new files
11 logout Logs you out of the system
12 echo Displays whatever follows to the standard output (screen)
Copies the source file into destination (destination can be
13 cp <source> <dest>
file or directory)
14 mv <source> <dest> Rename the source file as destination
Remove the file(s) given as arguments; can also be used
15 rm <file>
with the –rf option to remove a directory that is non-empty
16 bc Starts the calculator programme
Displays word, character and line count of the file (or
17 wc
standard input)
18 head Displays the first few lines of a file
19 tail Displays the last few lines of a file
Search for the given pattern and print those lines that have
20 grep
that pattern
Print the file structure of the given directory (or current
21 tree
directory)
22 chmod Change permissions of a file
Exercises

1. Make a directory called assign1 under your home directory.


2. Change to this directory.
3. Make three empty files: file1 file2 and file3.
4. Change back to your home directory.
5. Store the list of all the directories (long listing) in a file called dirfile.
6. Display the contents of dirfile on the screen.
7. Display on the screen the current time in the format hh:mm:ss.
8. Copy /home/manojkannan/FILE1.txt as file1 under the directory assign1.
9. Make assign1 as your current directory.
10. Execute a sequence of commands so that file2 contains the first five lines
and the last ten lines of file1. (you can use more than one command for this
task).
11. Count the number of times the word program appears in file1. (Hint: -o
option)
12. Change access privileges of file2 such that none except you can modify it but
every user (including you) can read and execute it.
13. Print only the total number of lines of file1 and file2.
14. Print the current file structure of your home directory.

15. Open file3 using vi editor and add the following line of text to it: This is file3!
16. Save and exit editing file3.
17. Append the contents of file2 to file3.
18. Open file3 using vi editor again, and insert the following line after the first
line: (25 stars)
*************************
19. Insert such a line after the last line of file3, just by using vi commands (that
is, do not type out the line again).
20. Save the modified file into another file named file4.
21. Now, count the number of characters in file4, without exiting vi editor.
22. Exit vi editor, so that none of these changes you made is recorded in file3.

You might also like