0% found this document useful (0 votes)
73 views8 pages

Linux Commands: username@User-PC: $ PWD /home/username

The document describes common Linux commands like pwd, mkdir, ls, cd, cat, head, tail, cp, mv, rmdir, rm, cal and date. It provides the command name, usage and examples of how to use each command to navigate directories, view and manipulate files and get system information. Key commands covered include those for creating, deleting and moving files/directories, viewing file contents, and getting the date and time.

Uploaded by

Pradip Bastola
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views8 pages

Linux Commands: username@User-PC: $ PWD /home/username

The document describes common Linux commands like pwd, mkdir, ls, cd, cat, head, tail, cp, mv, rmdir, rm, cal and date. It provides the command name, usage and examples of how to use each command to navigate directories, view and manipulate files and get system information. Key commands covered include those for creating, deleting and moving files/directories, viewing file contents, and getting the date and time.

Uploaded by

Pradip Bastola
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

LINUX COMMANDS

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.

4.cat (short for ‘concatenate’)


Command Name & Description: cat – It is one of the most frequently used command in
Linux operating system. cat command allows us to create single or multiple files, view
contents of file.
Eg: username@User-PC:~$ cd textfile1 - It takes us to textfile1 directory.
username@User-PC:~/textfile1$ cat > doc1 - It makes doc1 file in textfile1 directory.
I am learning Linux. And i am doing well. – Here we can write the contents for file doc1.
(go to new line & press ctrl+D to come out)
username@User-PC:~/textfile1$ ls - It lists the files inside directory textfile1.
doc1 - doc1 is shown since we have created it above using cat command.
username@User-PC:~/textfile1$ cat doc1 – using just cat doc1, we can see its contents.
I am learning Linux. And i am doing well.
username@User-PC:~/textfile1$ cat -n doc1
1 I am learning Linux. And I am doing well. - (It shows the number of lines in the file ).

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).

You might also like