0% found this document useful (0 votes)
5 views19 pages

Essential Unix Commands Guide

The document provides a comprehensive overview of various Unix commands, including their purposes, syntax, and examples. Key commands covered include 'passwd' for changing passwords, 'logout' for ending sessions, 'who' for listing logged-in users, and 'ls' for listing files and directories. Additional commands such as 'cat', 'cd', 'pwd', and file manipulation commands like 'rm', 'mkdir', and 'chmod' are also detailed, along with information on redirection, piping, and pattern searching with 'grep'.

Uploaded by

jatinchauhan6560
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)
5 views19 pages

Essential Unix Commands Guide

The document provides a comprehensive overview of various Unix commands, including their purposes, syntax, and examples. Key commands covered include 'passwd' for changing passwords, 'logout' for ending sessions, 'who' for listing logged-in users, and 'ls' for listing files and directories. Additional commands such as 'cat', 'cd', 'pwd', and file manipulation commands like 'rm', 'mkdir', and 'chmod' are also detailed, along with information on redirection, piping, and pattern searching with 'grep'.

Uploaded by

jatinchauhan6560
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

Unix command

Login Commands
 Passwd
 Logout
 Who
 Whoami
 clear

[Link]
 Purpose : This command is used to change the password for user
account. A normal user may only change the password for his\her
Own account while the super user may change the password for any
account
 Usage : It first asks for the old password this password is checked
with the stored password for this user, if it is valid it asks for the new
password and confirm password.
Options
 -d, --delete Delete a user’s password (make it empty).
 -l, --lock Lock the named account. This option disables an account by
changing the password
 -u, --unlock Unlock the account.

 Syntax : $passwd
 Example : $passwd
 Output :
old password :
new password :
confirm password :

[Link] / exit
 This command terminate the session and quite the current login.
Logout command allows you to programm automatically logout from
your session causes the session manager to take the requested action
immediately. Short key (ctrl + d) also used for logout.
 Syntax : $logout
 Example : $logout
 Output : to logout from current user session will be loged out.
[Link]
 This command displays all the users who are currently log into the system.
It returns the username, the terminal (Device id) and login time of the user.
 Syntax : $who
 Example : $who
 Output : who- show who is logged on.

Options :
 -l,--login print system login process.
 -q ,--count all login names and number of user logged on.
 -u ,--users List of logged in.

[Link] am I
 Instead of getting information about all user who are currently login, if
you want to get information about yourself then who am I is used.
 Who command with the arguments “am I” gives the details of the user who
executes this command.
 Syntax : $whoami
 Example : $whoami

[Link]
 This command clears the terminal screen. It takes no arguments or ignores
any command line arguments. It works similar to that of cls command in
Dos.
 Syntax : $clear
 Example : $clear

[Link]
 ls (List Directories) : It lists the directories and files in the current
directory.
Option :
 ls –l : Long listing of file showing with seven attributes (File Type,
Permission Links, Owner, Group, File Size, Last Modified, File Name).
 ls –n : It displays the user group id with long list format.
 ls –a : It is used to display hidden files.
 ls –R : It displays Folder and Subfolder.
 ls -c : it display List entries by column.
 ls -g : it display List without user/owner name.
 ls -G :( no-group) In a long list don’t print group name.
 ls -m : fill width with a comma separated list of entries.
 ls -s :sort by file size.
 ls -r ,--reverse : reverse order while starting.
 ls -t : sort by notification time.
 ls -x : list entries by lines instead of by columns.

Example :
$ls
Output :
Display List of files and folder from current directory.
7. cat
The cat (short for concatenate) command is one of the most frequently used
command in Linux/Unix like operating system.
Cat command allows us to create single or multiple files view contain of file and
redirect output in terminal or files.
This command is generally used to create a file, see the content of the file and
append data to a file.
Syntax: cat [option] [file name]…
Example :

 create two file with cat command

$ cat >[Link]
This is sample text file.
$cat >[Link]
This is unix command.
 To display content of file.

$cat [Link]
Output : This is sample text file.
 To display content of all text files.

$cat *.txt
Output :
This is sample text file.
This is unix command.
 To concatenate two files.

$ cat [Link] [Link] > [Link]


Output :
This is sample text file.
This is unix command.
8. cd
It is stands for change directory. Using this command you can move from
one directory to another by changing the directory in inner structure.
Syntax : cd [folder name]
Example : cd abc
Output : /abc

cd..
It is stands for change directory. This command is used to move from one
directory to another directory in up level in directory.
 Move up one folder

$cd..
 Get back to original location.

$cd
[Link]
print name of current working directory. The current directory is nothing
but the directory in which you are currently operating while using bush or ksh.
Syntax : $ pwd
Example : To print current working directory.
$ pwd
Output :
Home/lab
10. rm
rm remove each specified file by default. It does not remove directories.
It is stands for remove. It is used to delete the link to the file. It doesn’t
mean that the file is physically deleted. You can remove multiple files using a
single command.
Syntax: $rm [option] filename..
Example : $rm [Link]

11. mkdir
It is stands for make directory. This command is used to create
directories and sub directories. We can create multiple directories using a
single command.
Create the directory(ies).if they do not already exist.
Syntax : $mkdir [foldername]
Example : $ mkdir mydir
$ ls
mydir
12. rmdir
It is stands for remove directory. It is used to remove the one or more
directories. If the directory contains the files, it can not be remove and error
massage “directory is not empty” is return to the user.
Remove the directory. If they are empty.
Syntax : $rmdir [directory name]
Example : $rmdir mydir
13. wc (word count)
It is stands for word count. It is used to count the number of lines, words
and characters in the given file name.
Option :
wc -l : count no. of lines.
wc -c: count no. of characters.
wc -w: count no. of words.
Syntax : $wc [option] filename
Example : A file [Link] having following data.
This is number
12345
$wc [Link]
Output :
2 8 25 [Link]
Note : spacebar and enter also consider as character.

[Link]
The mv command allows you to move and remove content of file .
It is stands for move. It is used to rename a file as well as move a file to a
different directory.
Syntax : $mv [option] source target.
Example : $mv [Link] [Link]

15. cp
To copy one or more files to another location.
Syntax : cp <source file> <destination file>
Example : $cp [Link] [Link]
$cat [Link]
$cat [Link]
16. Ln
Create link between files. This command create a link file from source
file.
Syntax : $ln <file1> <file2>
Example : $cat > [Link]
hi to all
^z
$ln [Link] [Link]
$cat [Link]
lshi to all
17. head
head command help in viewing lines at the begining of the file
respectively.
Syntax : $ head [line number] file name
Example : $ head -5 [Link]
Output :Print 5 lines beginning of file.
[Link]
Tail command help in viewing lines at the ending of the file respectively.
Syntax : $ tail [line number] file name
Example : $ tail -3 [Link]
Output : print 3 lines end of file.
19. touch
This command changes the last modification time of the file.
Syntax : $ touch <file name>
Example : $ touch [Link]
$ls –l
[Link]
If the file size is larger than the screen then the content of the file with
scroll up until it reach at the end of file. User is only able to view the last
page.
Option :
-c : page through the file by clearing the window.(not scrolling).
-d : display “press space to continue”,’q’ to quit
-w : waits for a user to free a key before exiting.
-n : display n lines per window.

Syntax : $ more <file name>


Example : $more [option][file]

Ls | more
List the contents of the current directory with ls using more to
display the list one screen at a time.

21. less
This is command is used to see the information of the document page
wise this command and it is older version.

Syntax : $ less <file name>


Example : $ less [Link]

22. pg
Pg is a pager it allows you to view text files once a page at a [Link]
display a text file on a CRT one screenful at once after each page, a prompt is
displayed. The user may then either press the newline key to view the next
page or one of the keys described below.
Syntax : [option] [files]
Example : $ pg [Link]
Display the first screenful of the content of text file [Link] and a prompt
(“:”),pressing the return key display the next page.

[Link]
Chmod changes the permissions of each given file according the mode
where mode describes the permission to modify mode can be specified with
octal number or with letters.
Syntax: $Chmod [option]…mode
Example :
 Read by owner only
$ chmod 400 [Link]
 Read by group only
$chmod 040 [Link]
 Read by anyone
$chmod 004 [Link]

 Write by owner only


$chmod 200 [Link]
 Write by group only
$chmod 020 [Link]
 Write by anyone
$chmod 002 [Link]

 Execute by owner only


$chmod [Link]
 Execute by group only
$ chmod 010 [Link]
 Eecute by anyone
$chmod 001 [Link]

 Allow read permission to owner and group and anyone.


$chmod 444 [Link]
 Allow everyone to read,write,and execute file
$chmod 777 [Link]

24. find
The find command in unix is a command line utility for walking a file
hirarachy. It can be used to find file and directories and perform subsequent
operation on them it supports searching by file,folder,name,creation
date,modification date,owner and permission.
To find a single file by name pass the name option to find along with the
name of the file you are looking for.
Suppose the following directory structure exists shown here as the
output of the tree command
User
Abc
Mydir
[Link]
The file [Link] can be located with the find by using the name option
Find/user-name [Link]
Example :
Find
/user/mydir/[Link]

 Redirection & piping

Redirection is a feature in Linux such that when executing a


command you can change the standard input/output
[Link] basic workflow of any linux command is that it takes
an input and give an output.
The standard input (stdin) device is the keyword. The standard
output (stdout) device is the screen.
Output redirection
The ‘>’ symbol is used for output(stdout) redirection
Eample :
ls -l >listing
there the output of command ls -l is redirected to file “listing” instead of
your screen.

>> : Does the same as >, except that I & the target file [Link] new data are
appended.
Command >> [Link]
If [Link] exists the output of command will be appended to it after whatever is
already in it. If it does not exists it will be created.
Input redirection
The ‘<’ symbol is used for input (stdin) redirection.
Example : the mail program in Linux can help you send emails from the
terminal.
You can type the contents of the email using the standard device keyword but
if you want to attach a file to email you can use the input redirection operation
in the following format.
Mail’s “subject” to address < filename

<< : A here document it is often used to print multiline strings.


Command << word text word here command will take everything until it finds
the next accurance of word text in the next above as input.
Piping operator:
The pipe operator it passes of one command as input to
another. A command built from the pipe operator is called pipeline.

Command 1 | command 2
Any output printed by command is passed as output to
command 2
grep,fgrep,egrep

grep : ( globally search a regular expression and print) this


command can be used in search a pattern in one or more files
directly from the command line.
Syntax :
[option] patterns filename
Example
$grep “Linux ” [Link]
Welcome to Linux
In the output above the line in the file [Link] containing the
pattern or string “Linux ” was displayed as output
$grep “Linux” [Link]
If it is descried the grep command should ignore the case sensitive
the option -l can be used.
$grep -i can be used.
$ grep-i “Linux” [Link]
Welcome to Linux
If more than one file is supplied in argument list then grep searches
for the pattern or string in all the files.

For example :
$grep “Linux” [Link] [Link]
[Link] : welcome to Linux
[Link] : I hope you enjoyed working on linux
The grep command also allows the usage of regular expression in
pattern matching.
#grep -r “.*Linux “ [Link] [Link]
I hope you will have fun will Linux.

fgrep : (finding pattern in files)


fgrep
fgrep searches for fixed -character string in a files
fgrep is useful when you need to search for strings which
contain losts of regular expression meta character such as “$” , “A”
etc.
Syntex :
Fgrep [option] pattern filename
Example
$grep “support /help/ indos”.[Link]
Search for patterns of support and windows in the file [Link]
Egrep:
Egrep is pattern searching command which belongs to the
family of grep functions.
If there are several files with the matching pattern,it also display the
file names for each line.
Syntax :
Egrep [option] Pattern filesname
Example:
Egerp “Linux” [Link]

Cut :
Cut command is basically used for extracting the vertical
columns or set of character from either standard input from one or
more files.
Option :
-f : extract a set of specified fileds.
Imageine we have got a file numbers text which cosist of three
column
$cat [Link]
Col1 col2 col3
One two three
Four five six
In the following example cut will return only column
Example : $ cut -f2 [Link]
Output: col2
Two
five
in the next example cut will return column2 and 3
example : $cut -f1,3 [Link]
output: col1 col3
one three
four six
paste :
paste command combines the line together. These line can be
from multiple files.
$ paste file1 file3
1 ABC 1 101
2 DEF 2 102
3 EFG 3 103

Join :
It is used join two files.
Example:
$ join file1 file2
1 ABC 101
2 DEF 102
3 EFG 103
Sort :
It is arranged the data in ascending and descending order.
Example:
$sort [Link]
$sort -r [Link]
Cmp :
This command compares two files.
$cmp [Link] [Link]

Comm:
This command is useful to compare two sorted files line by line.
-1 : lines unique to file1
-2 : lines unique to file2
-3 :lines that appear in both files
Syntax :
$ comm [option] file name
Example:
$comm [option] [Link] [Link]

Diff:
This command finds difference between two files.
Example:
$diff [Link] [Link]
Tr :
This command is useful for changing the case from upper to
lower.
tr[option] ‘ set1‘ ‘set2’
$cat file | tr “[a-z]” “[A-Z]”

Sed:
Sed is a stream editor used for modifying the files in unix(linux).
Example
$sed ‘s/unix/linux/’ [Link]
Od:
Od command in linux is used to output the contents of a file in
different format being the default.
Syntax : $ od[option]… [file]
Example : $od -b [Link]
Tee
Tee copies data from standard input to each File and also to
standard output.
Syntax : tee [option] [file]
Example : ls -l *.txt | wc -l |tee [Link]

Script : script makes a type script of everything printed on your


terminal
Syntax : script [-a] [file]
Example : $script -a [Link]
Cal :
To display a calender.
Syntax : $cal
Example : $cal
Date :
To display systems date.
Syntax : $date
Example : $date
Factor :
It is used to print prime factors of the given number.
Syntax:
$factor [Number]
Example : $ factor 10
25
Ps :
It is used to display information about active process.
Example : $ps
Mount :
It is used to mounts a storage device or file system.
Example :
$mount
Umount :
It is used to umount a mounted filesystem.
$umount

You might also like