OS Commands
What happens when a user logs in?- Authentication - verifying that user name and password provided are valid
- .profile file present in the user's home directory will be executed to configure the environment
- User will land in user's home directory
What happens when a command is executed?- Whenever a command is executed, an attempt will be made to locate the binary/executable file for that command in all the path(s) associated with that user in addition to PWD.
- If the binary is located in any of the path(S) or PWD and user has execute permission on that command/binary/program, then that command/binary/program will be executed. (It does this by searching for an executable or script in the directories listed in the environment variable PATH)
Some special characters we should be aware of while dealing with commands~ tilda! exclamation or not@ at the rate # hash$ dollar% percent or modulo^ carat& and or ampersand* star or wildcard( ) round/parentheses brackets[ ] square brackets or arrays{ } curly/flower brackets<> Angle brackets- minus or hypen or dash_ underscore+ plus or addition or sum or concatenate= equal to; semi colon: colon" " double quotes' ' single quotes` ` back tics< less than> greater than, comma? question mark/ forward slash or division\ backward slash| pipe. dot or period\t tab\n new line
#################################################################################Notes for Commands begins here
A Command is a specific instruction given to computer to perform a specific task.Command can be executed in multiple ways depending on the situation/requirement. At times, we don't specify an option or argument and system will take an option or argument by itself and it is called default option or argument.- Command
- Command with option(s)
- Command with argument(s)
- Command with option(s) and arguments
Option: Command and option are separated by space. An option would usually follow command and start/prefixed with -(usually called as hyphen or minus or dash). A command can have 0(zero) or more options and it totally depends on the situation.I think it's better to explain with example.command -option(s)command -option1 -option2...-optionn
>id (Here "id" is command. 1 command, 0 or no option)>id -u (Here "id" is command and "u" is option. 1 command, 1 option)>id -u -n (or) id -un (Here "id" is command and "u" and "n" are options. 1 command, 2 options)
Argument: Command and argument are separated by space. A command can have 0(zero) or more arguments and it totally depends on the situation.I think it's better to explain with example.command argument(s)command -argument1 -argument2...-argumentn
id (Here "id" is command. 1 command, 0 or no argument)id jamesbond (Here "id" is command and "jamesbond" is argument. 1 command, 1 argument)touch f1 f2 (Here "touch" is command and "f1" and "f2" are arguments. 1 command, 2 arguments)
To summarize, - options starts with -
- both option and argument follow command
- both option and argument are separated by space
Before we take a deep dive, as per my understanding commands can be broadly categorized into following. Let's also understand what a command is.- Navigation - these will help in navigating around the servers
- pwd
- cd
- ls
- Generic commands
- date
- uname
- uptime
- clear
- man
- hostname
- history
- fc -l -100
- tty
- whoami (id -un)
- who
- w (uptime + who)
- init (init 0 - shutdown, init 6 - reboot)
- finger
- whereis
- which
- su
- sleep
- ifconfig
- exit
- echo ($SHELL, $HOME, $USER, $PWD, $PATH, $$, $?, $#, $*, )
- useradd
- passwd
- userdel
- groupadd
- groupdel
- usermod
- id
- nohup
- jobs
- env
- export
- Ctrl + c
- Ctrl + z
- File handling commands (In UNIX/Linux, both File and Directory will be referred as file) - these will help to take some specific action on files
- mkdir
- touch - Create a blank file or change file’s last modified time
- rmdir
- rm (we have to be very careful with this command)
- chmod
- chown
- chgrp
- cp
- mv
- ln (>ln -s <originalfile> <linkname>)
- gzip
- gunzip
- unzip
- tar (-t, -v, -f, -x, -c, -C)
- file
- umask (Files - 0666 and Directory 0777)
- stat
- mount
- scp
- To view contents of files - these will help to view, filter the content of file or output of commands
- cat
- more
- less
- head
- tail
- grep (just like Ctrl + f in Windows)
- sort
- uniq
- cut
- tr
- awk
- diff
- sdiff
- paste
- wc (-l, -w, -c)
- vi editor
- Monitoring related commands - these will help to monitor the performance of Server
- top in Linux /topas in AIX
- ps
- du
- df
- free
- vmstat
- ping
- ssh
- nslookup
- kill
Let's look at each command in detail######################
pwd command begins here
Command: pwd
Purpose: display/print the current/present directory on standard output(screen);
Options:- NONE
Arguments- NONE
Syntax:- >pwd
Example:- >pwd
pwd command ends here
######################
cd command begins here
Command: cd
Purpose: change from current directory to target directory
Options:- NONE
Arguments- <target_directory>
Syntax:- >cd <target_directory>
Example:
Let's take "/tmp" as directory here
- >cd /tmp
Notes:
Root Directory: / (root or slash)top-most directory in any UNIX file system structure. Some call it slash and some call it as root
Current Directory: . (to be read as dot)default location for working with files
Parent Directory: ..directory immediately above the current directory
Previous Working Directory: - (hyphen)Navigates to the previous working directory
Home Directory: ~ (to be read as tilda)- directory owned by a user
- default location when user logs in
- default home directory for a user will be /home/<username>
- User’s home directory can also be denoted by ~<username>
Root user’s home directory: /rootcontains files related to root user
Normal user’s home directory by default is /home/<username> However, it is always best to use ~<username> to refer a home directory of usercontains files related to that particular user
cd command ends here
######################
ls command begins here
Command: ls
Purpose:
to display the contents of a given directory (or)
to display the details of a given file (or)
to display the contents of current directory by default (if no argument is given)
Options:
- -l long listing
- -t display as per last modified timestamp
- -r display the output in reverse order
- -R display the contents of a directory "recursively"
- -i display the inode
- -A display hidden/system files excluding . and ..
- -a display hidden/system files including . and ..
- -h human readable form (works only in Linux)
Arguments- file (or)
- directory (or)
- Default argument will be "pwd"
Syntax:
>ls>ls -[options]>ls [filename or directoryname]>ls -[options] [filename or directoryname]
Example:- ls
- ls -l
- ls -ltr (or) ls -l -t -r (or) ls -l -r -t
- ls -ltr /etc/passwd
- ls -ltr /home/db2inst1
Example 1
db2inst2@db2v10P:~> ls -ltr Desktop/total 62604-rw-r--r-- 1 db2inst2 dbginst2 64025748 Jul 23 22:57 firefox-68.0.1.tar.bz2drwxr-xr-x 2 db2inst2 dbginst2 4096 Aug 12 20:41 testdrwxr-xr-x 2 db2inst2 dbginst2 4096 Aug 12 20:41 test1db2inst2@db2v10P:~>
Example 2 - In this case, all the options have been used; contents of sub directories, hidden files (.temp_Jay, . and .. ), and file size is 62M (human readable form) are all displayed
db2inst2@db2v10P:~> ls -ltrRaih Desktop/Desktop/:total 62M1237686 -rw-r--r-- 1 db2inst2 dbginst2 62M Jul 23 22:57 firefox-68.0.1.tar.bz21581113 drwxr-xr-x 26 db2inst2 dbginst2 4.0K Aug 9 22:14 ..1663142 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 test1663140 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 test11638564 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:45 .temp_Jay1638704 drwxr-xr-x 4 db2inst2 dbginst2 4.0K Aug 12 20:45 .
Desktop/test:total 8.0K1663145 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:41 test_F11663142 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 .1638704 drwxr-xr-x 4 db2inst2 dbginst2 4.0K Aug 12 20:45 ..
Desktop/test1:total 8.0K1663147 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:41 test1_F21663146 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:41 test1_F11663140 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 .1638704 drwxr-xr-x 4 db2inst2 dbginst2 4.0K Aug 12 20:45 ..db2inst2@db2v10P:~>
NotesIn the output of "ls -ltr" command,- if the first line is "total 0", then given argument is "empty dir"
- if the first line is "total n" (where is n is any positive number), then given argument is "non empty dir"
- if the first line doesn't contain word "total", then given argument is "file"
ls command ends here
######################
Command: manPurpose: To know details of a command
Options: To know details of a commandArguments To know details of a commandSyntax: To know details of a commandExample: To know details of a command
######################
cat command begins hereCommand: cat
Purpose: to display content of file on standard output(screen) or concatenate contents of files
Options:- -n to print line number against each line printed on screen
- -b to print line number against each non empty line printed on screen
- -evt to display special characters in the file
Arguments- <filename>
- <filename1> <filename2>
Syntax:- cat <filename>
- cat -[options] <filename1>
- cat -[options] <filename1>, <filename2>...
- cat <filename1> <filename2>
- <standard_output> | cat -[options]
Example:
Let's take "animals" as filename here
- cat animals
- cat -n animals
- ls -ltr | cat -n #this will assign a line number to each line in the output of command
cat command ends here
######################
more command begins here
Command: more
Purpose: display content of file page by page on standard output(screen); this will not return the prompt and will have to hit “q” key to return to prompt
Options:- NONE
Arguments- <filename>
Syntax:- >more <filename>
Example:
Let's take "animals" as filename here
- >more animals
Notes:Ctrl+f (or) Space bar to move forward page by pageCtrl +b to move backward page by pageReturn key to move forward line by line
more command ends here
######################
less command begins hereCommand: less (works only in Linux)
Purpose: display content of file page by page on standard output(screen); this will not return the prompt and will have to hit “q” key to return to prompt
Options:- NONE
Arguments- <filename>
Syntax:- >less <filename>
Example:
Let's take "animals" as filename here
- >less animals
Notes:Ctrl+f (or) Space bar to move forward page by pageCtrl +b to move backward page by pageReturn key to move forward line by lineDown arrow to move forward line by lineUp arrow to move backward line by line
less command ends here
######################
head command begins here
Command: head
Purpose: display top n lines of file on standard output(screen)
Options:- By default, head will print first 10 lines of file
- <number> to display top <number> lines of file
Arguments- <filename>
Syntax:- >head <filename>
- >head –<number> <filename>
- output | head –<number>
Example:
Let's take "animals" as filename here - head animals -This will display top 10 lines of "animals" file
- head -4 animals - This will display top 4 lines of "animals" file
head command ends here
######################
tail command begins here
Command: tail
Purpose: display bottom n lines of file on standard output(screen)
Options:- By default, tail will print bottom10 lines of file
- <number> to display bottom <number> lines of file
Arguments- <filename>
Syntax:- >tail <filename>
- >tail -<number> <filename>
- output | tail -<number>
Example:
Let's take "animals" as filename here - tail animals -This will display bottom 10 lines of "animals" file
- tail -4 animals - This will display bottom 4 lines of "animals" file
tail command ends here
######################
cp command begins here
Command: cp
Purpose: similar to copy and paste in Windows OS. Creates copy of file in target location with a copy in source location
Options:- -p to preserve the permissions
- -R to copy directories reecursively
Arguments- <source_filename> – name of file to be copied
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>.)
Syntax:- >cp <source_filename> <target_location>
- >cp <source_filename > <target_location>/<target_filename> (just like Save As in Windows)
- >cp -R <source_dirname> <target_location>
- >cp -R <source_dirname> <target_location>/<new_dirname>
Example:
Let's take "animals" as filename here - cp animals . -to copy "animals" file to current directory with same name
- cp animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name “animals1”
Notes:
- During cp and mv, usually file will be copied with same name unless a new name is specified
cp command ends here
######################
mv command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
mv command ends here
######################
grep command begins here
Command: grep
Purpose: to search for a string (or) pattern in a file and print the line containing the same
Options:- -i case insensitive search
- -n print the line number along with line
- -v print all the lines which doesn’t contain matching pattern
- -c print the count of lines which contain matching pattern/word
- -w search for exact match of the pattern/word
- -E Search for multiple patterns/words (-E “<pattern1>|<pattern2>” include pattern in double quotes)
Arguments- <pattern or word or string> -word or string or pattern to be searched
- <filename> or <stream of data>
Syntax:- >grep –option(s) <pattern> <filename>
- >grep –option(s) <pattern> <filename1> <filename2> <filename3>
- >Stream of data | grep –option(s) <pattern>
Example:- >grep db2inst1 /etc/passwd -this will search for "db2inst1" in /etc/passwd file
- >ls –ltr | grep ^d -to print all the lines which begin with d (only directories will be listed) in the output of >ls
- >cat /etc/passwd | grep –i james -this will perform a case insensitive search for james in /etc/passwd file. Similar outcome can also be achieved using >grep –i james etc/passwd
grep command ends here
######################
sort command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
sort command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
| pipe
cmd1 | cmd2
Output of cmd1 will be given as input to cmd2
Command mkdir Purpose To create a directory Options -p --> to create parent directory if it doesn't exist Arguments directory_name Syntax mkdir <directory_name>
mkdir <directory_name1> <directory_name2> ... (we can create more than 1 directory in 1 go Example mkdir a1 --> This will create a directory a1mkdir a1 a2 --> This will create two directories a1 and 2mkdir -p a1/b1 --> This will create a1 followed by b1 if a1 doesn't exist
- Authentication - verifying that user name and password provided are valid
- .profile file present in the user's home directory will be executed to configure the environment
- User will land in user's home directory
- Whenever a command is executed, an attempt will be made to locate the binary/executable file for that command in all the path(s) associated with that user in addition to PWD.
- If the binary is located in any of the path(S) or PWD and user has execute permission on that command/binary/program, then that command/binary/program will be executed. (It does this by searching for an executable or script in the directories listed in the environment variable PATH)
~ tilda
! exclamation or not
@ at the rate
# hash
$ dollar
% percent or modulo
^ carat
& and or ampersand
* star or wildcard
( ) round/parentheses brackets
[ ] square brackets or arrays
{ } curly/flower brackets
<> Angle brackets
- minus or hypen or dash
_ underscore
+ plus or addition or sum or concatenate
= equal to
; semi colon
: colon
" " double quotes
' ' single quotes
` ` back tics
< less than
> greater than
, comma
? question mark
/ forward slash or division
\ backward slash
| pipe
. dot or period
\t tab
\n new line
- Command
- Command with option(s)
- Command with argument(s)
- Command with option(s) and arguments
Option: Command and option are separated by space. An option would usually follow command and start/prefixed with -(usually called as hyphen or minus or dash). A command can have 0(zero) or more options and it totally depends on the situation.
I think it's better to explain with example.
command -option(s)
command -option1 -option2...-optionn
>id (Here "id" is command. 1 command, 0 or no option)
>id -u (Here "id" is command and "u" is option. 1 command, 1 option)
>id -u -n (or) id -un (Here "id" is command and "u" and "n" are options. 1 command, 2 options)
Argument: Command and argument are separated by space. A command can have 0(zero) or more arguments and it totally depends on the situation.
I think it's better to explain with example.
command argument(s)
command -argument1 -argument2...-argumentn
id (Here "id" is command. 1 command, 0 or no argument)
id jamesbond (Here "id" is command and "jamesbond" is argument. 1 command, 1 argument)
touch f1 f2 (Here "touch" is command and "f1" and "f2" are arguments. 1 command, 2 arguments)
To summarize,
- options starts with -
- both option and argument follow command
- both option and argument are separated by space
Before we take a deep dive, as per my understanding commands can be broadly categorized into following. Let's also understand what a command is.
- Navigation - these will help in navigating around the servers
- pwd
- cd
- ls
- Generic commands
- date
- uname
- uptime
- clear
- man
- hostname
- history
- fc -l -100
- tty
- whoami (id -un)
- who
- w (uptime + who)
- init (init 0 - shutdown, init 6 - reboot)
- finger
- whereis
- which
- su
- sleep
- ifconfig
- exit
- echo ($SHELL, $HOME, $USER, $PWD, $PATH, $$, $?, $#, $*, )
- useradd
- passwd
- userdel
- groupadd
- groupdel
- usermod
- id
- nohup
- jobs
- env
- export
- Ctrl + c
- Ctrl + z
- File handling commands (In UNIX/Linux, both File and Directory will be referred as file) - these will help to take some specific action on files
- mkdir
- touch - Create a blank file or change file’s last modified time
- rmdir
- rm (we have to be very careful with this command)
- chmod
- chown
- chgrp
- cp
- mv
- ln (>ln -s <originalfile> <linkname>)
- gzip
- gunzip
- unzip
- tar (-t, -v, -f, -x, -c, -C)
- file
- umask (Files - 0666 and Directory 0777)
- stat
- mount
- scp
- To view contents of files - these will help to view, filter the content of file or output of commands
- cat
- more
- less
- head
- tail
- grep (just like Ctrl + f in Windows)
- sort
- uniq
- cut
- tr
- awk
- diff
- sdiff
- paste
- wc (-l, -w, -c)
- vi editor
- Monitoring related commands - these will help to monitor the performance of Server
- top in Linux /topas in AIX
- ps
- du
- df
- free
- vmstat
- ping
- ssh
- nslookup
- kill
pwd command begins here
Command: pwd
Purpose: display/print the current/present directory on standard output(screen);
Options:
- NONE
Arguments
- NONE
Syntax:
- >pwd
Example:
- >pwd
pwd command ends here
######################
cd command begins here
Command: cd
Purpose: change from current directory to target directory
Options:
- NONE
Arguments
- <target_directory>
Syntax:
- >cd <target_directory>
Example:
Let's take "/tmp" as directory here
- >cd /tmp
Notes:
Root Directory: / (root or slash)
top-most directory in any UNIX file system structure. Some call it slash and some call it as root
Current Directory: . (to be read as dot)
default location for working with files
Parent Directory: ..
directory immediately above the current directory
Previous Working Directory: - (hyphen)
Navigates to the previous working directory
Home Directory: ~ (to be read as tilda)
- directory owned by a user
- default location when user logs in
- default home directory for a user will be /home/<username>
- User’s home directory can also be denoted by ~<username>
Root user’s home directory: /root
contains files related to root user
Normal user’s home directory by default is /home/<username>
However, it is always best to use ~<username> to refer a home directory of user
contains files related to that particular user
cd command ends here
######################
ls command begins here
Purpose:
to display the contents of a given directory (or)
to display the details of a given file (or)
to display the contents of current directory by default (if no argument is given)
Options:
- -l long listing
- -t display as per last modified timestamp
- -r display the output in reverse order
- -R display the contents of a directory "recursively"
- -i display the inode
- -A display hidden/system files excluding . and ..
- -a display hidden/system files including . and ..
- -h human readable form (works only in Linux)
Arguments
- file (or)
- directory (or)
- Default argument will be "pwd"
Syntax:
>ls
>ls -[options]
>ls [filename or directoryname]
>ls -[options] [filename or directoryname]
Example:
- ls
- ls -l
- ls -ltr (or) ls -l -t -r (or) ls -l -r -t
- ls -ltr /etc/passwd
- ls -ltr /home/db2inst1
Example 1
db2inst2@db2v10P:~> ls -ltr Desktop/
total 62604
-rw-r--r-- 1 db2inst2 dbginst2 64025748 Jul 23 22:57 firefox-68.0.1.tar.bz2
drwxr-xr-x 2 db2inst2 dbginst2 4096 Aug 12 20:41 test
drwxr-xr-x 2 db2inst2 dbginst2 4096 Aug 12 20:41 test1
db2inst2@db2v10P:~>
Example 2 -
In this case, all the options have been used; contents of sub directories, hidden files (.temp_Jay, . and .. ), and file size is 62M (human readable form) are all displayed
db2inst2@db2v10P:~> ls -ltrRaih Desktop/
Desktop/:
total 62M
1237686 -rw-r--r-- 1 db2inst2 dbginst2 62M Jul 23 22:57 firefox-68.0.1.tar.bz2
1581113 drwxr-xr-x 26 db2inst2 dbginst2 4.0K Aug 9 22:14 ..
1663142 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 test
1663140 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 test1
1638564 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:45 .temp_Jay
1638704 drwxr-xr-x 4 db2inst2 dbginst2 4.0K Aug 12 20:45 .
Desktop/test:
total 8.0K
1663145 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:41 test_F1
1663142 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 .
1638704 drwxr-xr-x 4 db2inst2 dbginst2 4.0K Aug 12 20:45 ..
Desktop/test1:
total 8.0K
1663147 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:41 test1_F2
1663146 -rw-r--r-- 1 db2inst2 dbginst2 0 Aug 12 20:41 test1_F1
1663140 drwxr-xr-x 2 db2inst2 dbginst2 4.0K Aug 12 20:41 .
1638704 drwxr-xr-x 4 db2inst2 dbginst2 4.0K Aug 12 20:45 ..
db2inst2@db2v10P:~>
Notes
In the output of "ls -ltr" command,
- if the first line is "total 0", then given argument is "empty dir"
- if the first line is "total n" (where is n is any positive number), then given argument is "non empty dir"
- if the first line doesn't contain word "total", then given argument is "file"
ls command ends here
######################
Command: man
Purpose: To know details of a command
Options: To know details of a command
Arguments To know details of a command
Syntax: To know details of a command
Example: To know details of a command
######################
cat command begins here
Command: cat
Purpose: to display content of file on standard output(screen) or concatenate contents of files
Options:
- -n to print line number against each line printed on screen
- -b to print line number against each non empty line printed on screen
- -evt to display special characters in the file
Arguments
- <filename>
- <filename1> <filename2>
Syntax:
- cat <filename>
- cat -[options] <filename1>
- cat -[options] <filename1>, <filename2>...
- cat <filename1> <filename2>
- <standard_output> | cat -[options]
Example:
Let's take "animals" as filename here
- cat animals
- cat -n animals
- ls -ltr | cat -n #this will assign a line number to each line in the output of command
cat command ends here
######################
more command begins here
Command: more
Purpose: display content of file page by page on standard output(screen); this will not return the prompt and will have to hit “q” key to return to prompt
Options:
- NONE
Arguments
- <filename>
Syntax:
- >more <filename>
Example:
Let's take "animals" as filename here
- >more animals
Notes:
Ctrl+f (or) Space bar to move forward page by page
Ctrl +b to move backward page by page
Return key to move forward line by line
more command ends here
######################
less command begins here
Command: less (works only in Linux)
Purpose: display content of file page by page on standard output(screen); this will not return the prompt and will have to hit “q” key to return to prompt
Options:
- NONE
Arguments
- <filename>
Syntax:
- >less <filename>
Example:
Let's take "animals" as filename here
- >less animals
Notes:
Ctrl+f (or) Space bar to move forward page by page
Ctrl +b to move backward page by page
Return key to move forward line by line
Down arrow to move forward line by line
Up arrow to move backward line by line
less command ends here
######################
head command begins here
Command: head
Purpose: display top n lines of file on standard output(screen)
Options:
- By default, head will print first 10 lines of file
- <number> to display top <number> lines of file
Arguments
- <filename>
Syntax:
- >head <filename>
- >head –<number> <filename>
- output | head –<number>
Example:
Let's take "animals" as filename here
- head animals -This will display top 10 lines of "animals" file
- head -4 animals - This will display top 4 lines of "animals" file
head command ends here
######################
tail command begins here
Command: tail
Purpose: display bottom n lines of file on standard output(screen)
Options:
- By default, tail will print bottom10 lines of file
- <number> to display bottom <number> lines of file
Arguments
- <filename>
Syntax:
- >tail <filename>
- >tail -<number> <filename>
- output | tail -<number>
Example:
Let's take "animals" as filename here
- tail animals -This will display bottom 10 lines of "animals" file
- tail -4 animals - This will display bottom 4 lines of "animals" file
tail command ends here
######################
cp command begins here
Command: cp
Purpose: similar to copy and paste in Windows OS. Creates copy of file in target location with a copy in source location
Options:
- -p to preserve the permissions
- -R to copy directories reecursively
Arguments
- <source_filename> – name of file to be copied
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>.)
Syntax:
- >cp <source_filename> <target_location>
- >cp <source_filename > <target_location>/<target_filename> (just like Save As in Windows)
- >cp -R <source_dirname> <target_location>
- >cp -R <source_dirname> <target_location>/<new_dirname>
Example:
Let's take "animals" as filename here
- cp animals . -to copy "animals" file to current directory with same name
- cp animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name “animals1”
Notes:
- During cp and mv, usually file will be copied with same name unless a new name is specified
cp command ends here
######################
mv command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
mv command ends here
######################
grep command begins here
Command: grep
Purpose: to search for a string (or) pattern in a file and print the line containing the same
Options:
- -i case insensitive search
- -n print the line number along with line
- -v print all the lines which doesn’t contain matching pattern
- -c print the count of lines which contain matching pattern/word
- -w search for exact match of the pattern/word
- -E Search for multiple patterns/words (-E “<pattern1>|<pattern2>” include pattern in double quotes)
Arguments
- <pattern or word or string> -word or string or pattern to be searched
- <filename> or <stream of data>
Syntax:
- >grep –option(s) <pattern> <filename>
- >grep –option(s) <pattern> <filename1> <filename2> <filename3>
- >Stream of data | grep –option(s) <pattern>
Example:
- >grep db2inst1 /etc/passwd -this will search for "db2inst1" in /etc/passwd file
- >ls –ltr | grep ^d -to print all the lines which begin with d (only directories will be listed) in the output of >ls
- >cat /etc/passwd | grep –i james -this will perform a case insensitive search for james in /etc/passwd file. Similar outcome can also be achieved using >grep –i james etc/passwd
grep command ends here
######################
sort command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
sort command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
cmd1 | cmd2
Output of cmd1 will be given as input to cmd2
Command | mkdir |
Purpose | To create a directory |
Options | -p --> to create parent directory if it doesn't exist |
Arguments | directory_name |
Syntax | mkdir <directory_name> mkdir <directory_name1> <directory_name2> ... (we can create more than 1 directory in 1 go |
Example | mkdir a1 --> This will create a directory a1 mkdir a1 a2 --> This will create two directories a1 and 2 mkdir -p a1/b1 --> This will create a1 followed by b1 if a1 doesn't exist |
File handling commands (In UNIX/Linux, both File and Directory refer to a file)
1.
1.
To view contents of files
1.
1.
Monitoring related commands
- ps
- du
- df
- free
- vmstat
- ping
- ssh
- nslookup
- kill
######################
top in Linux /topas in AIX command begins here
Command: top
Purpose: this is analogous to Task Manager in Windows where
Options:- NA
Arguments- NA
Syntax:- >top or >topas
Notes:We don't user Options or Arguments
top in Linux /topas in AIX command ends here
######################
ps command begins here
Command: ps
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
ps command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:- NA
Arguments- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here - >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
kill command begins here
Command: kill
Purpose: to stop a process when it couldn't be stopped gracefully
Options:- -9
Arguments- <PID> (process ID)
Syntax:- >kill <PID>
- >kill -9 <PID>
Example:
>kill -9 1234here 1234 is the Process ID (PID) of the process to be stopped
kill command ends here
######################1.
- ps
- du
- df
- free
- vmstat
- ping
- ssh
- nslookup
- kill
######################
top in Linux /topas in AIX command begins here
Command: top
Purpose: this is analogous to Task Manager in Windows where
Options:
- NA
Arguments
- NA
Syntax:
- >top or >topas
Notes:
We don't user Options or Arguments
top in Linux /topas in AIX command ends here
######################
ps command begins here
Command: ps
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
ps command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
uniq command begins here
Command: mv
Purpose: similar to cut and paste in Windows OS. Creates copy of file in target location with out a copy in source location
Options:
- NA
Arguments
- <source_filename> – name of file to be moved
- <target_location> (or) <target_location>\<target_filename>
(If <target_filename> is not specified, then <source_filename> would be considered as <target_filename>)
Syntax:
- >mv <source_filename> <target_location>
- >mv <source_filename > <target_location>/<target_filename>
Example:
Let's take "animals" as filename here
- >mv animals . -to copy animals file to current directory with same name
- >mv animals /tmp/animals1 -to copy animals file in current directory to /tmp with different name "animals1"
Notes:
During cp and mv, usually file will be copied with same name unless a new name is specified
uniq command ends here
######################
kill command begins here
Command: kill
Purpose: to stop a process when it couldn't be stopped gracefully
Options:
- -9
Arguments
- <PID> (process ID)
Syntax:
- >kill <PID>
- >kill -9 <PID>
Example:
>kill -9 1234
here 1234 is the Process ID (PID) of the process to be stopped
kill command ends here
######################
1.
No comments:
Post a Comment