Linux CMD
Linux CMD
Linux CMD
The date command display the current date with day of week, month, day, time
(24 hours clock) and the year.
SYNTAX: $ date
2. The echo’command:
SYNTAX: $ echo
EXAMPLE: $ echo “God is Great”
Unix offers an online calculator and can be invoked by the command bc.
SYNTAX: $ bc
EXAMPLE: bc –l
16/4
5/2
The who command is used to display the data about all the users who are currently
logged into the system.
SYNTAX: $ who
The who am i command displays data about login details of the user.
SYNTAX: $ who am i
7. The ‘id’ command
SYNTAX: $ id
The tty (teletype) command is used to know the terminal name that we are using.
SYNTAX: $ tty
SYNTAX: $ clear
The man command gives you complete access to the Unix commands.
The ps command is used to the process currently alive in the machine with the 'ps'
(process status) command, which displays information about process that are alive when you run
the command. 'ps;' produces a snapshot of machine activity.
SYNTAX: $ ps
EXAMPLE: $ ps
$ ps –e
$ps -aux
12. The ‘uname’ command
The uname command is used to display relevant details about the operating system on the
standard output.
-s -> Displays the name of the operating system (i.e.. system name)
EXAMPLE: $ uname -a
The pwd (print working directory) command displays the current working
directory.
SYNTAX: $ pwd
The rmdir is used to remove a directory from the disk. Before removing a
directory, the directory must be empty (no files and directories).
SYNTAX: $ cd dirname
EXAMPLE: $ cd receee
The ls command displays the list of files in the current working directory.
SYNTAX: $ ls
EXAMPLE: $ ls
$ ls –l
$ ls –a
The cat command is also used to view the contents of a specified file.
The cp command is used to copy the contents of one file to another and copies the
file from one place to another.
SYNTAX: $ rm filename
EXAMPLE: $ rm rec
$ rm –f rec
Use option –fr to delete recursively the contents of the directory and its subdirectories.
5. The ‘mv’ command:
The mv command is used to move a file from one place to another. It removes a
specified file from its original location and places it in specified location.
The wc command is used to count the number of words, lines and characters in a file.
SYNTAX: $ wc filename
EXAMPLE: $ wc receee
The ls command lists the files on the terminal (screen). Using the redirection operator ‘>’
we can send the output to file instead of showing it on the screen.
EXAMPLE: $ who | wc -l
While using pipes, we have not seen any output from a command that gets piped into
another command. To save the output, which is produced in the middle of a pipe, the tee
command is very useful.
Metacharacters are special characters that are at higher and abstract level compared to
most of other characters in Unix. The shell understands and interprets these metacharacters in a
special way.
EXAMPLE:
$ ls r** - Displays all the files whose name begins with ‘r’
$ ls ?kkk - Displays the files which are having ‘kkk’, from the second characters
irrespective of the first character.
$ ls [a-m] – Lists the files whose names begins alphabets from ‘a’ to ‘m’
$ ls [!a-m] – Lists all files other than files whose names begins alphabets from ‘a’ to ‘m’
File permission is the way of controlling the accessibility of file for each of three users
namely Users, Groups and Others.
There are three types of file permissions are available, they are
r-read
w-write
x-execute
The permissions for each file can be divided into three parts of three bits each.
EXAMPLE: $ ls college
Where,
-rwx The file is readable, writable and executable by the owner of the file.
r-x Indicates the absence of the write permission by the Group owner of the file.
The chmod command is used to set the read, write and execute permissions for all
categories of users for file.
EXAMPLE:
$ chmod u –wx college
Removes write & execute permission for users for ‘college’ file.
Assigns read & write permission for users and groups for ‘college’ file.
Assigns absolute permission for groups of all read, write and execute permissions for
‘college’ file.
The file permissions can be changed using octal notations also. The octal notations for
file permission are
Read permission 4
Write permission 2
Execute permission 1
EXAMPLE:
Assigns all permission to the owner, read and write permissions to the group and only
executable permission to the others for ‘college’ file.
The semicolon(;) command is used to separate multiple commands at the command line.
SYNTAX: $ command1;command2;command3…………….;commandn
EXAMPLE: $ who;date
The ‘&&’ operator signifies the logical AND operation in between two or more valid
Unix commands.It means that only if the first command is successfully executed, then the next
command will executed.
The ‘||’ operator signifies the logical OR operation in between two or more valid Unix
commands.It means, that only if the first command will happen to be un successfully,it will
continue to execute next commands.
1.5 FILTERS
SYNTAX: $ ls –l | more
This command is used to search for a particular pattern from a file or from the
standard input and display those lines on the standard output. “Grep” stands for “global search
for regular expression.”
Arun cse
Ram ece
Kani cse
Arun cse
Kani cse
5. The ‘sort’ command:
The sort command is used to sort the contents of a file. The sort command reports only to
the screen, the actual file remains unchanged.
OPTIONS:
Command Purpose
Sort –r college Sorts and displays the file contents in reverse order
Sort –c college Check if the file is sorted
Sort –n college Sorts numerically
Sort –m college Sorts numerically in reverse order
Sort –u college Remove duplicate records
Sort –l college Skip the column with +1 (one) option.Sorts according to
second column
The nl filter adds lines numbers to a file and it displays the file and not provides access to
edit but simply displays the contents on the screen.
SYNTAX: $ nl filename
EXAMPLE: $ nl college
We can select specified fields from a line of text using cut command.
OPTION:
6. ping
It is used verify that a device can communicate with another on network. PING stands for
Packet Internet Groper.
synopsis- ping [options]
[root@localhost ~]# ping 172.16.4.1
PING 172.16.4.1 (172.16.4.1) 56(84) bytes of data.
64 bytes from 172.16.4.1: icmp_seq=1 ttl=64 time=0.328 ms
64 bytes from 172.16.4.1: icmp_seq=2 ttl=64 time=0.228 ms
64 bytes from 172.16.4.1: icmp_seq=3 ttl=64 time=0.264 ms
64 bytes from 172.16.4.1: icmp_seq=4 ttl=64 time=0.312 ms
^C
--- 172.16.4.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.228/0.283/0.328/0.039 ms
7. ifconfig
It is used configure network interface.
synopsis- ifconfig [options]
example
[root@localhost ~]# ifconfig
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.6.102 netmask 255.255.252.0 broadcast 172.16.7.255
inet6 fe80::4a0f:cfff:fe6d:6057 prefixlen 64 scopeid 0x20<link>
ether 48:0f:cf:6d:60:57 txqueuelen 1000 (Ethernet)
RX packets 23216 bytes 2483338 (2.3 MiB)
RX errors 0 dropped 5 overruns 0 frame 0
TX packets 1077 bytes 107740 (105.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
8. traceroute
It tracks the route the packet takes to reach the destination.
synopsis- traceroute [options]
example
[root@localhost ~]# traceroute www.rajalakshmi.org
traceroute to www.rajalakshmi.org (220.227.30.51), 30 hops max, 60 byte packets
1 gateway (172.16.4.1) 0.299 ms 0.297 ms 0.327 ms
2 220.225.219.38 (220.225.219.38) 6.185 ms 6.203 ms 6.189 ms