Linux Shell Commands - Part 4


Welcome to Part 4 of Linux Shell Commands, Lets look at some other interesting commands.


1. Displaying contents of a Directory.

   'ls' command is used for this purpose.

    a. 'ls' with no options displays the names of the files in the directory, excluding hidden files, and other details of the files.
   
    root@bt:~/Desktop/Ckorner/post4# ls
    file1.txt  file2.txt  part4  testDir1  testDir2
   
root@bt:~/Desktop/Ckorner/post4#

    b. 'ls -l' displays contents in long format
   
root@bt:~/Desktop/Ckorner/post4# ls -l
    total 20
    -rw-r--r-- 1 root root   65 2012-07-09 00:24 file1.txt
    -rw-r--r-- 1 root root   65 2012-07-09 00:25 file2.txt
    -rw-r--r-- 1 root root    2 2012-07-09 00:21 part4
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir1
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir2
    
root@bt:~/Desktop/Ckorner/post4#

    c. 'ls -la' displays in long format including hidden files.

   
root@bt:~/Desktop/Ckorner/post4# ls -la
    total 36
    drwxr-xr-x 6 root root 4096 2012-07-09 00:26 .
    drwxr-xr-x 6 root root 4096 2012-07-09 00:20 ..
    -rw-r--r-- 1 root root   65 2012-07-09 00:24 file1.txt
    -rw-r--r-- 1 root root   65 2012-07-09 00:25 file2.txt
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 .hiddenDir1
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 .hiddenDir2
    -rw-r--r-- 1 root root    2 2012-07-09 00:21 part4
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir1
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir2
   
root@bt:~/Desktop/Ckorner/post4#

    d. 'ls -lt' displays contents in long format sorting the order of recent files created being at the top and older being at the bottom.

   
root@bt:~/Desktop/Ckorner/post4# ls -lt
    total 20
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir2
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir1
    -rw-r--r-- 1 root root   65 2012-07-09 00:25 file2.txt
    -rw-r--r-- 1 root root   65 2012-07-09 00:24 file1.txt
    -rw-r--r-- 1 root root    2 2012-07-09 00:21 part4
   
root@bt:~/Desktop/Ckorner/post4#

    e. 'ls -ltr' is the reverse of 'ls -lt', displays the older files at the top and recent files being at the bottom.

   
root@bt:~/Desktop/Ckorner/post4# ls -ltr
    total 20
    -rw-r--r-- 1 root root    2 2012-07-09 00:21 part4
    -rw-r--r-- 1 root root   65 2012-07-09 00:24 file1.txt
    -rw-r--r-- 1 root root   65 2012-07-09 00:25 file2.txt
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir1
    drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir2
   
root@bt:~/Desktop/Ckorner/post4#

    f. 'ls -lth' displays in long format + sorted with older files at bottom and recent files at top + file size

   
root@bt:~/Desktop/Ckorner/post4# ls -lth
    total 20K
    drwxr-xr-x 2 root root 4.0K 2012-07-09 00:26 testDir2
    drwxr-xr-x 2 root root 4.0K 2012-07-09 00:26 testDir1
    -rw-r--r-- 1 root root   65 2012-07-09 00:25 file2.txt
    -rw-r--r-- 1 root root   65 2012-07-09 00:24 file1.txt
    -rw-r--r-- 1 root root    2 2012-07-09 00:21 part4
   
root@bt:~/Desktop/Ckorner/post4#

    g. 'ls -lti' displays in long format + sorted with older files at bottom and recent files at top + inode number

   
root@bt:~/Desktop/Ckorner/post4# ls -lti
    total 20
    418058 drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir2
    418057 drwxr-xr-x 2 root root 4096 2012-07-09 00:26 testDir1
    418056 -rw-r--r-- 1 root root   65 2012-07-09 00:25 file2.txt
    418055 -rw-r--r-- 1 root root   65 2012-07-09 00:24 file1.txt
    418054 -rw-r--r-- 1 root root    2 2012-07-09 00:21 part4
   
root@bt:~/Desktop/Ckorner/post4#

    h. 'ls -ld <dir name>' displays the properties of the directory.

   
root@bt:~/Desktop/Ckorner/post4# cd ..
   
root@bt:~/Desktop/Ckorner# ls -ld post4/
    drwxr-xr-x 6 root root 4096 2012-07-09 00:26 post4/
   
root@bt:~/Desktop/Ckorner#

    i. 'ls -ltrhi' displays all the mentioned above, together.

   
root@bt:~/Desktop/Ckorner# cd post4/
   
root@bt:~/Desktop/Ckorner/post4# ls -ltrhia
    total 36K
    412958 drwxr-xr-x 6 root root 4.0K 2012-07-09 00:20 ..
    418054 -rw-r--r-- 1 root root    2 2012-07-09 00:21 part4
    418055 -rw-r--r-- 1 root root   65 2012-07-09 00:24 file1.txt
    418056 -rw-r--r-- 1 root root   65 2012-07-09 00:25 file2.txt
    418057 drwxr-xr-x 2 root root 4.0K 2012-07-09 00:26 testDir1
    418058 drwxr-xr-x 2 root root 4.0K 2012-07-09 00:26 testDir2
    418059 drwxr-xr-x 2 root root 4.0K 2012-07-09 00:26 .hiddenDir1
    418060 drwxr-xr-x 2 root root 4.0K 2012-07-09 00:26 .hiddenDir2
    418053 drwxr-xr-x 6 root root 4.0K 2012-07-09 00:26 .
   
root@bt:~/Desktop/Ckorner/post4#

2. Clearing the screen:

    'clear' command is used to clear the screen.

3. Resetting the screen:

    'reset' is used to reset the screen buffer.

4. Checking Properties of a File.

    'stat' command is used to check all the properties of a file.

   
root@bt:~/Desktop/Ckorner/post4# stat file1.txt
      File: `file1.txt'
      Size: 65              Blocks: 8          IO Block: 4096   regular file
    Device: 806h/2054d      Inode: 418055      Links: 1
    Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
    Access: 2012-07-09 00:25:14.907267102 +0530
    Modify: 2012-07-09 00:24:52.707267112 +0530
    Change: 2012-07-09 00:24:52.707267112 +0530
   
root@bt:~/Desktop/Ckorner/post4#

Thats all for this post, Stay Tuned for more. :)

Feel Free To Leave A Comment
If Our Article has Helped You, Support Us By Making A Small Contribution, Thank You!

1 comment:

  1. Great delivery. Great arguments. Keep up the good
    spirit.
    My blog ; simple beach wedding dresses

    ReplyDelete