Command | Description |
---|---|
General Commands | |
clear | Clears the Linux/Unix terminal screen |
date | Displays the system date and time |
cal | It Displays calander |
type | Tells about type of command (whether internal or external) |
alias | Creates alias of existing command |
pwd | Shows your current working directory |
man | Shows various options associated with a particular command |
who | Display the user details who is currently login |
File and Directory related Commands | |
touch | Creates the empty file(s) if it does not exist, Otherwise change the timestamp of file |
cat | 1.creates the file and save the content 2.Display the file contents 3.Append the content in existing file |
file | Displays wether its file or directory |
more | Pagewise display with % |
less | Pagewise display without % |
mkdir | Creates the new directory |
cd | To change the directory |
rm | To remove or delete the files / directories |
rmdir | To remove a empty directory |
ls | To list all files and directories of target directory |
cp | Copy file(s) from source to destination |
mv | Move the file(s) from source to destination |
ln | To make hard or soft link netween the files |
Text Processing Commands | |
paste | To combine the content of file files line by line and printing the files content horizontally |
wc | Displays the no of lines words and characters of any data |
head | Displays the lines from top to bottom as per option given |
tail | Displays the lines from bottom to top as per option given |
cut | Used to retrieves specific characters or fields from data or file |
tr | Used on out put of some other command to translate characters |
sort | Used to sort data, by default sorting happens as per the English disctionary |
grep | Used to pattern search in the given file |
uniq | Removes adjacent repeated lines in given data of file |
cmp | Used to compare two files, Its pinpoints at only first diffrence |
comm | Used to compare two files but can be apply only on sorted files |
Process and Memory Related Commands | |
ps | Displays the list of process submitted to kernel |
pstree | Displays the process in the form of tree diagram |
bg | Displays the status of process running in background |
fg | Used to bring any background job in foreground |
nice | Execute a command with updated scheduling priority |
kill | Used to send signal to perticular process |
nohup | Execute the command in background even after user get log out |
df | Print the system disk space usage and available |
du | Estimate file space usage in current directory |
Compression Utilities Commands | |
gzip | -To compress and decompress the file(s) -Compressed file(s) gets .gz extension |
gunzip | Used to decompress the file having extension of .gz Works same as gzip -d file.gz |
zip | -Use to compress file(s) to avoid compatibility problemsand with non-Linux users. |
unzip | -To extract the contents of a zip file. |
zcat | Displays the contents of compressed files |
zmore | Used to view content pagewise of compressed file |
tar | -Used to create a tape archive file -Extract from archive file |
Find Command | |
Find is one of the powerful utility of Unix/Linux used for searching the files or group
of in a directory hierarchy.
Syntax :
$ find [pathname] [expression]
Examples on the find utility :
1). How to find file 'abc.txt' from home directory downwards and print them ?
$ find ~ -name abc.txt -print
or
$ find ~ –type f –name abc.txt –print
2). How to find which ends with any digits and begin with 'abc' from home
directory downwards and print them ?
$ find ~ -name "abc[0-9]" -print
3). How to find a directory name 'dirname' from home directory downwards and
print them ?
$ find ~ -type d -name dirname -print
4). How to search a character special file 'abc.txt' from current directory ?
$ find . -type c -name abc.txt -print
5). How to find file in current directory , which has inode value 76538 ?
$ find . –inum 76538 –print
6). How to find all files from current directory , which have 2 links ?
$ find . –links 2 –print
7). How to find all files from current directory , which have more than 2 links ?
$ find . –links +2 –print
8). How to find all files from current directory , which have less than 4 links ?
$ find . –links -4 –print
9). How to find all files from home directory downwards, which have permissions
755 ?
$ find ~ –perm 755 –print
10). How to search a block special file ‘abc.txt’ from home directory downwards
and print them?
$ find ~ –type b –name abc.txt –print
11). How to search a file ‘abc.txt’ from home directory downwards whose owner
is ‘mukesh’ ?
$ find ~ \( –user mukesh –a –name abc.txt \) –print
12). How to search all files from home directory downwards, which have size
1 MB
$ find ~ –size 1M –print
13). How to search a file 'file.txt' from current directory downwards and execute
'rm' command on the result ?
$ find . –name file.txt –exec rm {} \;
14). How to search a file 'file.txt' from current directory and execute 'rm'
command on the result after confirmation ?
$ find . –name file.txt –ok rm {} \;
( or ) $ find . –name file.txt –exec rm –i {} \;
15). How to search the file 'abc.txt' in the current directory and three levels down
to the current directory ?
$ find -maxdepth 4 -name "abc.txt"
16). How to print the files in the sub-directories between level 1 and 5 ?
$ find -mindepth 2 -maxdepth 6 -name "abc.txt"
17). How to find the empty files in current directory?
$ find . maxdepth 1 -empty
18). How to find all files in current directory?
find . -maxdepth 1 -type f
|
|
Communication Commands | |
write command Send a message to another user who is logged in. Syntax
$ write <user_name> Example
mithun.s@mks-laptop:~$ write mukesh.kumar write: mukesh.kumar is logged in more than once; writing to pts/0 hi mukesh ,how are you ? in above command mithun.s sending message to mukesh.kumar as 'hi mukesh ,how are you ?' Now mukesh.kumar will get this on his terminal as below
mukesh.kumar@mks-laptop:~$ Message from mithun.s@mks-laptop on pts/2 at 13:32 ... hi mukesh mesg command allow and disallow to other user to send message to you. Syntax
$ mesg y[or n] Example
$ mesg -- Displays the status as below is y Disallow other users to send you message.
$ mesg n $ mesg -- Now it displays the status as below is n To allow other users to send you message type
$ mesg y Note : Even if user disables the message he/she would receive the messages from the root. wall command Send a message to all the logged in user who having message recieving permission as yes. Syntax
$ wall [-n] [-t TIMEOUT] [file] -n : no banner -t : timeout ,default time out is 300 sec Example
$ wall hello world Broadcast message from root (pts/1) (Thu Feb 27 15:06:04 IST 2014): hello world ftp command Ftp (File Transfer Protocol) is the user interface to the Internet standard File Transfer Protocol. The program allows a user to transfer files to and from a remote network site. Syntax
$ ftp [hostname] put command to copy one file from the local machine to the remote machine
$ put filename get command To copy one file from the remote machine to the local machine
$ get filename To copy multiple files from the local machine to the remote machine; you are prompted for a y/n answer before transferring each file
$ mput file1 [file2...] copy all from the local machine to the remote machine,which are starting from 'f'.
$ mput f* To copy multiple files from the remote machine to the local machine; you are prompted for a y/n answer before transferring each file
$ mget file1 [file2...] To copy all files from remote machine to the local machine which are starting from 'f'.
$ mget f* To exit the FTP environment (same as quit)
$ bye To terminate a connection with another computer System will give “Good Bye” message then type bye
$ close To request a list of all available FTP commands
$ help or $ ? User can also type ‘?’ symbol for to list all FTP command
![Command] Syntax $ ![Command [arg...]] Used to execute any command in local machine It shifts the control from ftp prompt to local machine
$ ! This will shift the control from ftp prompt to local machine. Now user can perform any operation in local system by using the command prompt. To shift the control back to ftp prompt, use exit command. |
Commands in detail
Clear Command
It will clear your linux/unix terminal screen
$ clear
date command
To display the system date and time ,it will give the below output
$ date
Fri Feb 21 00:56:30 IST 2014
Fri Feb 21 00:56:30 IST 2014
cal command
1.To display the calendar for current month
$ cal
2. To display the calendar for Jan month(month value 01) for 2014
$ cal 01 2014
3. To display the complete calendar of year 2007
$ cal 2007
Type command
To check whether clear command is internal or external
$ type clear
clear is /usr/bin/clear
clear is /usr/bin/clear
Above command showing one path in output, means it is stored as a file, so clear is
external command.
Now let us check whether alias command is internal or external
$ type alias
alias is a shell builtin
It is displaying the message “alias is a shell built-in”, so alias is internal command.
alias Command
To create alias name of an existing command
$ alias c=clear
now you can use only command 'c' instead of clear ,but its scope remain for the
current terminal
Who command
To display the details of all users who are currently logged in
$ who -- Displays the self details as below
mukesh.kumar tty7 2014-02-26 19:26 (:0)
mukesh.kumar pts/0 2014-02-26 23:24 (:0.0)
$ who i am
O/P: mukesh.kumar pts/5 2014-02-24 17:43 (:0.0)
O/P: mukesh.kumar pts/5 2014-02-24 17:43 (:0.0)
man command
This command can be use to find the various option associated with particular command.
Syntax :
man <command name>
To see the various option associated with who command on terminal type below command
$ man who
pwd command
This command will show your present working directory.
$ pwd -- will show as below
/home/mukesh.kumar/Desktop/Ayush_patient_data
/home/mukesh.kumar/Desktop/Ayush_patient_data
touch command
Used to create the empty file ,it is also used to change the timestamp of existing files
Syntax
$ touch [option] file_name(s)
Examples
To create multiple empty file at a time ,type below command
$ touch file1 file2 file3 file4
To change both the access and modification times to the current time of existing file file1
$ touch -am file1
To use the times of file1 for file2, use oprion -r(reference) as below
$ touch -r file1 file2
The -d and -t options allow the user to add a specific last access time, to change the last access time of file1 to 10 Mar 2014 09:30 would be enclosed in single quotes
and used as follows
$ touch -d '1 Mar 2014 09:30' file1
cat command
Cat can be used for the following purpose
1.To reading or display the content of file
2.New file creation
Syntax
$ cat [option] [filename]
Examples
To reading or display content of file1 ,write below command
$ cat file1
To display the content of more than one files
$ cat file.txt abc.txt f1.txt
The above command will display the content of files in same order ,first it will show the content of file.txt then below that abc.txt then in last f1.txt
To create a new file and writing some content in file.
$ cat > file1.txt
----
----
ctr+d (to save all content in file1.txt)
----
----
ctr+d (to save all content in file1.txt)
Note : if file1.txt already exist then new data will get override.
To append the data in existing file
$ cat >> file1.txt
----
----
write some data and hit 'ctr+d' to save the file1.txt
----
----
write some data and hit 'ctr+d' to save the file1.txt
file command
To check type of file ie: whether it is file or directory.
Syntax
$ file [option] [file/dirname]
more command
To display page wise ,useful when file having more pages which can not be display at a time on the computer screen.
The more command allow you to reading the content from page1
$ more file1.txt
less command
Similar to more command.
This command allows you to view a text file without fear of accidently modifying it, as you would with a text editor
$ less file1.txt
mkdir command
Creates the directory in the current directory, if they do not already exist.
Syntax
$ mkdir [option] [dirname]
Examples
To create a directory dir1 in current directory
$ mkdir dir1
To create a dir in a path ,suppose i would like to create a directory dir2 inside another directory name 'freelancer'
Then we need to give the path of the directory 'freelancer' followed by new directory 'dir2' as follow
$ mkdir /home/mukesh.kumar/Desktop/freelancer/dir2
(or)
--in general
$ mkdir path/dir2
(or)
--in general
$ mkdir path/dir2
To create the hierarchy of directories ,use -p(parents) option
$ mkdir –p dir1/dir2/dir3
cd command
To change the shell working directory
Following command will change current directory to dirname if dirname is present in current directory
$ cd dirname
To change the directory in the mentioned path
$ cd path/dir1
To changes to the home directory
$ cd (or) $ cd ~
To changes to the root directory (i.e. />)
$ cd /
To changes to the Parent directory
$ cd ..
rm command
Used to delete the file or directory.
Syntax
rm [option] [-r directories] [filename]
Examples
To remove multiple files
$ rm file1 file2 file3 [file4..]
To remove a directory recursively
$ rm -r dirname
To remove file interactively
$ rm -i filename.txt
rm: remove regular file `filename.txt'?
rm: remove regular file `filename.txt'?
Note : if rm command used by using '-i' option it will always ask user to confirm by displaying a message.
Removing forcefully
Assume filename is not having write permission for the user. If the user is giving the below command
$ rm filename
It will display confirmation message before removing the file.
But if user is giving the command with ‘-f’ option as follows:
$ rm –f file_name
It will remove the file forcefully without displaying confirmation message
To remove a file whose name starts with a `-', for example `-foo',
use one of these commands:
$ rm -- -foo
(or)
$ rm ./-foo
(or)
$ rm ./-foo
rmdir command
rmdir can be use to remove the empty directory
$ rmdir emptydir
ls (list) command
List information about the FILEs (the current directory by default).
Syntax
$ ls [option] [file]
Note : To check the various option ,use the following command
$ ls --help
Examples
To list all file and directories of current directory
$ ls
To list files and directories of target directory in long format
(includes accesspermissions, size of file, last modification date & time, no of links etc.)
$ ls -l
To list files and directories of target directory
$ ls dirname
To list all the files and directories (including hidden) of target directory
$ ls -a dirname
To list files and directories of target directory in reverse order.
$ ls -r dirname
Note : by default it shows in alphabetically.
To list files and directories of target directory with their inode value.
$ ls -i dirname
To list all the files and directories of target directory recursively
$ ls -R dirname
To list files and directories of target directory with information of format of file
(ie : directory name with ‘/’ as suffix, executable files with ‘*’ as suffix etc.)
$ ls -F dirname
To list with inode value
$ ls -i dirname
To list all the files and directories(including hidden files) of target directory in long format
$ ls -al dirname
To list files and directories with inode values recursively of target directory in long format
$ ls -iRl dirname
To list files and directories with last modified in reverse order
$ ls -ltr dirname
cp command
To copy files and directories from source to destination.
Synatx
$ cp [option] source destination
Examples
To create copy of file1.txt with name file2.txt in same directory
$ cp file1.txt file2.txt
To create copy of multiple source file(s) with same name in source directory
$ cp file1.txt [file2.txt] dirname
To copy dir1 or content of dir1 in dir2
$ cp -r dir1 dir2
Note : if dir2 is not present : create dir2 in current dir,copy content of dir1 in dir2
if dir2 present : COPY sub tree structure rooted at dir1 in dir2
( inside dir2 we will get dir1)
To copy files interactively. It will ask for confirmation by displaying a message to the user but only in the case of overwriting.
$ cp –i source destination
mv command
Used to rename source file/directory to destination name
Move source file/directory to destination directory
Syntax
$ mv [option] source destination
To rename source file with destination name
$ mv file1.txt file2.txt
To move source files in destination directory
$ mv file1.txt [file2.txt] dirname
To move dir1 or content of dir1 into dir2
$ mv -r dir1 dir2
Note : if dir2 is not present :rename dir1 with name dir2
if dir2 present then move sub tree structure rooted at dir1 in dir2
To Move or rename interactively. It will ask for confirmation by displaying a message to the user but only in the case of overwriting.
$ mv –i source destination
ln( link ) command
To create hard and soft link between the files
There are two types of link we can create
1.Hard Link :
While creating a link from source to Destination file.The changes done in the source file will be effected in destination file.
But when The source file is deleted the destination file remains the same.
2.Soft Link :
While creating a link using soft link from source to destination file → the changes done
in the source file will be effected in Destination file too.
But when the source file is deleted the destination file also gets invisible. i.e when u tried to check the destination file its says no such file or directory
To make hard link between the file
$ ln sourcefile destinationfile
To makes soft(or symbolic) link between files
$ ln -s source destination
Note : we can not create hard link for directory
No comments:
Post a Comment