0% found this document useful (0 votes)
104 views

Linux Commands

The document discusses Linux commands like pwd, mkdir, rmdir, ls, cd, cat, chmod, cp, mv, rm, more, diff, cmp, wc, od, lp, cal, date, who, tty and ln. It provides the usage, syntax and examples for each command and describes what each command is used for and how to execute it. The output and results of running the commands are also demonstrated.

Uploaded by

shahnaz husaini
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

Linux Commands

The document discusses Linux commands like pwd, mkdir, rmdir, ls, cd, cat, chmod, cp, mv, rm, more, diff, cmp, wc, od, lp, cal, date, who, tty and ln. It provides the usage, syntax and examples for each command and describes what each command is used for and how to execute it. The output and results of running the commands are also demonstrated.

Uploaded by

shahnaz husaini
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Command: pwd

Usage : display the full path for the Current working directory.
Syntax : pwd
Example : $pwd
Output :To view the directory path.

Command: mkdir
Usage : It is used to create a new directory.
Syntax : mkdir <directory name>
Example : $mkdir newdir
Output : Creates directory newDir

Command: rmdir
Usage: used to remove a directory specified in the command line. It
requires the specified directory to be empty before removing it.
Syntax: rmdir <directory name>
Example: $rmdir newdir
Output : deletes the directory newDir. newDir should be empty
Result: Thus the above Commands have been executed and checked the
output successfully.

Command: ls
Usage: display the files in the current working directory.
Syntax: ls [Options]
[Options]:
-l - list the files in the long format
-a - list all entries, including the hidden files
-d - list the directory files instead of its contents
-t - lists in order of last modification time
Examples: $ls
Output: list all files in specified directory.

Command: cd
Usage: Change from the current Working directory to any other directory
Specified.
Syntax: cd [DIRECTORY]
Command : cat
Usage : is used to display the contents of a small file on terminal.
Syntax : cat <option> <file name>
Option :
-s –Warning about non existing file.
Example: $cat sample3.txt
Output : To display the content of sample3 text file.

Command : Chmod
Usage : used to changing the permissions of the file.
File type: (i) owner (ii) group (iii) others
• Owner has all three permissions.
• Group has read and writes.
• Others have only read permission.
• read permission – 4, write – 2, execute 1
• eg. rwxrwr=764 , 673 = rwrwxwx
Syntax: chmod [OPTION] [MODE] [FILE]
Example: ˜$ chmod o+x Testing.java
˜$ ls -l Testing.java
Output: -rw-r--r-x 1 srihari srihari 3570 2009-03-23 10:
˜$ chmod 655 Testing.java
˜$ ls -l Testing.java
Output: -rw-r-xr-x 1 srihari srihari 3570 2009-03-23 10:

Command: cp
Usage : is used to create duplicate copies of ordinary files.
Syntax : cp [source file] [destination file]
Example: $cp testing.java testing1.java
Output : creates the copy of Testing1.java

Command: mv
Usage : is used to move or rename ordinary files and directories.
Syntax : mv [source file] [destination file]
Example: $mv testing.java test.java
Output : renames the file Testing.java to Test.java

Command: rm
Usage : It is used to remove the specified file in directory.
Syntax : rm [source file]
Example: rm file1
Output : To delete the text file name file1.
Command: more
Usage : is used to display the output of a command on the screen
SYSTEM ADMINISTRATION LAB MANUAL Page 9
page by Page.
Syntax : more [options] filename
Options :
n – skip n lines and display another screen [ n as an integer]
-h displays all the options in more
Example: $more test.java
Output: To display the output of test.java in page by page.

FILE COMMANDS:
Command: diff
Usage : is used to find difference between two files.
Syntax : diff [options..] from-file to-file
Options :
-w Ignore white space when comparing lines.
-a Treat all files as text and compare them line-by-line.
-b Ignore changes in amount of white space.
Example: $ diff -w file1.txt file2.txt

Command: cmp
Usage : is used to compare two files whether they are identical or
not.

Command: wc (statistic of file)


Usage : is used to count lines, words and characters, Depending on the
option used.
Syntax : wc [options] [file name]
Options :
-l: Number of lines
-w: Number of words
-c: Number of characters
Example : $ wc sample1.txt
Output : 65 2776 17333 sample1.txt
Which means sample1.txt file has 65 lines, 2776 words, and 17333
Characters.

Command: od
Usage : is used to display the actual file content on octal value
format.
Syntax: od [option] filename
Example: od -c file1.txt

Command: lp
Usage : is used to send file to a printer.
Syntax : ip [option] filename
Example : ip sample file
Output : To view the file on printer format.
Command : cal
Usage : is used to see calendar for any specific month or a complete year
Syntax : cal [ [month] year]
Example: $ cal April 2009
Output : April 2009
Su Mo Tu We Th Fr Sa
1234
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

Command : date
Usage : is used to display the current date.
Syntax : $ date
Options:
d - The day of the month (1-31)
y - The last two digits of the year
H,M,S - Hour Minute and second respectively
D - the date in mm/dd/yy
Example: $ date
Output: Tue Apr 21 21:33:49 IST 2009
Example: $ date +"%D %H:%M:%S"
Output: 04/21/09 21:35:02

Command: who
Usage : is used to list the users currently logged on to the system.
Syntax : $ who
Output:
srihari pts/0 2009-04-15 11:58 (:10.129.41.3)
nithin pts/1 2009-04-15 16:09 (:10.129.20.5)
avadhut pts/2 2009-04-13 14:39 (:10.129.45.20)
anil pts/3 2009-04-13 16:32 (:10.129.23.45)

Command : tty
Usage : The Linux "tty" command display the name of the connected
terminal.
Syntax : tty [OPTION]...
Example: [root@RHEL01 ~]# tty

Command : ln
Usage : is used to create link to a file (or) directory. It helps to
provide soft link for desired files.
Syntax : ln [options] existing file (or directory)name new file(or
directory)name
Options:
-n - Does not overwrite existing files.
-s - Used to create soft links
Example: ln -s file1.txt file2.txt
Output : Creates a symbolic link to 'file1.txt' with the name of 'file2.txt'.
Result:
Thus the above General purpose Commands have been executed and
checked
• The two files are compared byte by byte and the location of the first
mismatch is printed on the screen.
• If two files are identical, then it does not print anything on the screen
Syntax : cmp <file1> <file2>
Example: $ cmp sample1.txt sample2.txt

Command : cat
Usage : is used to when supplied with more than one file will concatenate
the files without any header information.
Syntax : cat <file name>
Example: $ cat sample3.txt sample4.txt
Output:
/*contents of sameple3.txt*/
/*followed by contents of sample4.txt
Result:
Thus the above Commands have been executed and checked the output
successfully.

You might also like