Linux Commands: username@User-PC: $ PWD /home/username
Linux Commands: username@User-PC: $ PWD /home/username
1.pwd
Command Name: pwd – Print the name of the current working directory.
Description: Print the name of the current working directory.
Eg: username@User-PC:~$ pwd
/home/username
Note: A file is a collection of data that is stored on disk and that can be manipulated as a
single unit by its name. A directory is a file that acts as a folder for other files.
2.mkdir, ls
Command Name: mkdir – make directories.
Description: Create directories, if they do not already exist.
Command Name: ls – list directory contents.
Description: List information about the contents of the directory.
Eg: username@User-PC:~$ mkdir textfile1 (It creates the directory named textfile1
at home directory.)
username@User-PC:~$ mkdir textfile2 (It creates the directory named textfile2
at home directory.)
username@User-PC:~$ ls ( It lists the directories present at home directory.)
textfile1 textfile2
3.cd
Command Name: cd – change directories
Description: It changes current directory to another directory. In other word, we use ‘cd’
command to go to a certain directory.
Eg: username@User-PC:~$ cd textfile1
username@User-PC:~/textfile1$
If we simply type cd, i.e, username@User-PC:~/textfile1$ cd
we get username@User-PC: ~$ i.e., we return to the default home directory.
5.head, tail
Command Name and Usage: head – Print the first 10 lines of the file.
tail – Print the last 10 lines of the file.
Eg: Let’s create a text file with more than 15 lines in it and try to display its 1st 10 and last
10 lines using head and tail command respectively.
username@User-PC:~/textfile1$ cat > doc2
Linux OS.
1
2
3
4
5
6
7
8
9
10
11
12
(Press cntrl+D to come out )
username@User-PC:~/textfile1$ cat doc2 (It shows all of its contents.
(See its output in Linux.)
username@User-PC:~/textfile1$ head doc2 (It shows first 10 lines.)
Linux OS.
1
2
3
4
5
6
7
8
9
username@User-PC:~/textfile1$ tail doc2 (It shows last 10 lines.)
(Check Output in Linux).
6.cp
Command Name & Usage: cp – copy files and directories. It is used to copy files or group
of files or directory from source to destination.
Eg: username@User-PC:~/textfile1$ ls
doc1 doc2
username@User-PC:~/textfile1$ cp doc1 doc2 (All contents of doc1 is copied to doc2.
Previous contents of doc2 is removed).
username@User-PC:~/textfile1$ cat doc2
I am learning Linux. And I am doing well.
username@User-PC:~/textfile1$ cp doc1 doc3 (There is no file named doc3 however ‘cp’
command creates a new file ‘doc3’ and
copy contents of doc1 to doc3).
username@User-PC:~/textfile1$ ls
doc1 doc2 doc3
username@User-PC:~/textfile1$ cat doc3
(Check output in Linux).
7. mv
Command Name & Usage: mv – move (rename) files. It renames or move source files or
directory to destination file or directory.
Eg: username@User-PC:~/textfile1$ ls
doc1 doc2 doc3
username@User-PC:~/textfile1$ mv doc1 doc3 (It moves/renames doc1 file to doc3).
username@User-PC:~/textfile1$ ls
doc2 doc3
username@User-PC:~/textfile1$ cat doc3
(Output Check in Linux).
8. rmdir, rm
Command Name & Usage: rmdir – It removes directory, if they are empty.
rm- It removes files.
Eg: username@User-PC:~/textfile1$ ls
doc2 doc3
username@User-PC:~/textfile1$ rm doc2
username@User-PC:~/textfile1$ ls
doc3 (doc2 has been removed by ‘rm’ command)
username@User-PC:~/textfile1$ rmdir doc3
rmdir: failed to remove 'doc3': Not a directory (doc3 is a file.)
username@User-PC:~/textfile1$ cd
username@User-PC:~$ ls
textfile1 textfile2
username@User-PC:~$ ls textfile1 (Shows files in textfile1 directory).
doc3
username@User-PC:~$ rmdir textfile1
rmdir: failed to remove 'textfile1': Directory not empty (So we have to first delete doc3).
For deleting doc3 we have to move into textfile1 directory.
username@User-PC:~$ cd textfile1
username@User-PC:~/textfile1$ rm doc3
username@User-PC:~/textfile1$ ls (it shows nothing because all files are deleted.)
(Now we can delete textfile1 directory since it is empty).
username@User-PC:~/textfile1$ cd
username@User-PC:~$ rmdir textfie1
username@User-PC:~$ ls
textfile2
9.cal, date:
Command Name and Usage: cal – calender, it displays the calender.
date- date, it displays date.
Eg: username@User-PC:~$ cal (Check Output).
username@User-PC:~$ cal -y (Check Output).
username@User-PC:~$ cal -j (Check Output).
username@User-PC:~$ cal -jy (Check Output).
username@User-PC:~$ date (Check Output).