Linux/Unix Simple Commands
Single Post
Header
Tuesday, September 1, 2015
Interview Linux/Unix Command Examples
1.Grep Command in Linux/Unix Examples :
a.Find the word present in a file
grep <word> <filename>
b.Find the word present in the current and sub directories
grep -r <word> .
"." <dot> represents the current directory and "-r" represents recursive
2.df command for disk free space in linux
[ivreddy@localhost test]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 16G 4.0G 11G 27% /
tmpfs 1012M 432K 1012M 1% /dev/shm
/dev/sda1 291M 30M 247M 11% /boot
/dev/sr0 46M 46M 0 100% /media/Reliance
[ivreddy@localhost test]$
3.top command gives an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive tasks on the system
[admin@localhost test]$ top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1942 root 20 0 75076 26m 8372 S 10.3 1.3 2:34.03 Xorg
2381 admin 20 0 315m 55m 23m S 3.3 2.7 4:56.94 firefox
2357 admin 20 0 51096 12m 9496 S 2.3 0.6 0:12.77 gnome-terminal
8161 admin 20 0 2676 1116 868 R 0.7 0.1 0:00.20 top
2242 admin 20 0 91836 21m 16m S 0.3 1.1 0:44.49 vmtoolsd
1 root 20 0 2852 1408 1192 S 0.0 0.1 0:02.27 init
4.sort command in linux
[ivreddy@localhost Desktop]$ cat file
linux
dos
unix
windows
unix
[ivreddy@localhost Desktop]$ sort file
dos
linux
unix
unix
windows
// sort -u <file> will display the uniq records
[ivreddy@localhost Desktop]$ sort -u file
dos
linux
unix
windows
// sort -r <file> will display the records in reverse order
[ivreddy@localhost Desktop]$ sort -r file
windows
unix
unix
linux
dos
[ivreddy@localhost Desktop]$
2.df command for disk free space in linux
[ivreddy@localhost test]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 16G 4.0G 11G 27% /
tmpfs 1012M 432K 1012M 1% /dev/shm
/dev/sda1 291M 30M 247M 11% /boot
/dev/sr0 46M 46M 0 100% /media/Reliance
[ivreddy@localhost test]$
3.top command gives an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive tasks on the system
[admin@localhost test]$ top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1942 root 20 0 75076 26m 8372 S 10.3 1.3 2:34.03 Xorg
2381 admin 20 0 315m 55m 23m S 3.3 2.7 4:56.94 firefox
2357 admin 20 0 51096 12m 9496 S 2.3 0.6 0:12.77 gnome-terminal
8161 admin 20 0 2676 1116 868 R 0.7 0.1 0:00.20 top
2242 admin 20 0 91836 21m 16m S 0.3 1.1 0:44.49 vmtoolsd
1 root 20 0 2852 1408 1192 S 0.0 0.1 0:02.27 init
4.sort command in linux
[ivreddy@localhost Desktop]$ cat file
linux
dos
unix
windows
unix
[ivreddy@localhost Desktop]$ sort file
dos
linux
unix
unix
windows
// sort -u <file> will display the uniq records
[ivreddy@localhost Desktop]$ sort -u file
dos
linux
unix
windows
// sort -r <file> will display the records in reverse order
[ivreddy@localhost Desktop]$ sort -r file
windows
unix
unix
linux
dos
[ivreddy@localhost Desktop]$
ls commands in Unix.Linux - with Examples
Different ls commands in Linux:
[admin@localhost Desktop]$ pwd
/home/admin/Desktop
[admin@localhost Desktop]$ ls
linux_grep new file new file (copy) test1.txt testfolder.zip
linux_grep.txt new file~ practice testfolder.rar zip unzip.txt
[admin@localhost Desktop]$ ls -l
total 48
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
[admin@localhost Desktop]$ ls -lt
total 48
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
[admin@localhost Desktop]$ ls -lrt
total 48
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
[admin@localhost Desktop]$ ls -ls
total 48
4 -rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
4 -rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
4 -rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
0 -rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
0 -rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
4 drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
4 -rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
4 -rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
4 -rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
20 -rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
[admin@localhost Desktop]$ ls -lrs
total 48
20 -rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
4 -rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
4 -rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
4 -rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
4 drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
0 -rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
0 -rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
4 -rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
4 -rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
4 -rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
[admin@localhost Desktop]$ ls -lsrt
total 48
4 -rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
4 -rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
4 -rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
0 -rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
4 -rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
4 -rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
4 -rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
20 -rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
4 drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
0 -rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
[admin@localhost Desktop]$ ls -la
total 56
drwxr-xr-x. 3 admin admin 4096 Oct 1 23:00 .
drwx------. 28 admin admin 4096 Oct 2 12:01 ..
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
[admin@localhost Desktop]$
[admin@localhost Desktop]$ pwd
/home/admin/Desktop
[admin@localhost Desktop]$ ls
linux_grep new file new file (copy) test1.txt testfolder.zip
linux_grep.txt new file~ practice testfolder.rar zip unzip.txt
[admin@localhost Desktop]$ ls -l
total 48
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
[admin@localhost Desktop]$ ls -lt
total 48
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
[admin@localhost Desktop]$ ls -lrt
total 48
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
[admin@localhost Desktop]$ ls -ls
total 48
4 -rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
4 -rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
4 -rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
0 -rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
0 -rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
4 drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
4 -rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
4 -rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
4 -rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
20 -rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
[admin@localhost Desktop]$ ls -lrs
total 48
20 -rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
4 -rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
4 -rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
4 -rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
4 drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
0 -rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
0 -rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
4 -rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
4 -rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
4 -rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
[admin@localhost Desktop]$ ls -lsrt
total 48
4 -rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
4 -rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
4 -rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
0 -rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
4 -rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
4 -rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
4 -rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
20 -rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
4 drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
0 -rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
[admin@localhost Desktop]$ ls -la
total 56
drwxr-xr-x. 3 admin admin 4096 Oct 1 23:00 .
drwx------. 28 admin admin 4096 Oct 2 12:01 ..
-rw-rw-r--. 1 admin admin 1286 Aug 22 22:05 linux_grep
-rw-rw-r--. 1 admin admin 3758 Aug 22 22:26 linux_grep.txt
-rw-rw-r--. 1 admin admin 20 Sep 20 12:50 new file
-rw-rw-r--. 1 admin admin 0 Sep 20 12:50 new file~
-rw-rw-r--. 1 admin admin 0 Oct 1 23:00 new file (copy)
drwxrwxr-x. 5 admin admin 4096 Oct 1 22:49 practice
-rw-rw-r--. 1 admin admin 184 Sep 20 12:41 test1.txt
-rw-rw-r--. 1 admin admin 220 Sep 20 17:38 testfolder.rar
-rw-rw-r--. 1 admin admin 390 Sep 20 12:59 testfolder.zip
-rw-rw-r--. 1 admin admin 20190 Oct 1 22:31 zip unzip.txt
[admin@localhost Desktop]$
Subscribe to:
Posts (Atom)