Tuesday, May 7, 2013

Daily used Linux/Unix commands



Command to list latest modified file from parent directory
ls –lRrta
Options:
-l for long listing
-R for recursive
-r for reverse listing
-t for sorting on modified time
-a for listing all including hidden files

Similar command on windows is: dir /N /S

Command to find a file from given path

find -name -print
e.g.
# find /etc -name "1000-gnu.java.security.provider.Gnu" -print
/etc/java/security/security.d/1000-gnu.java.security.provider.Gnu

Command to find a text by searching recursively entire directory contents
find -type f -print | xargs grep "text to search"
e.g.
# find DOWNLOADS/iotop-0.5/ -type f -print | xargs grep "import struct"
DOWNLOADS/iotop-0.5/build/lib/iotop/netlink.py:import struct
DOWNLOADS/iotop-0.5/build/lib/iotop/genetlink.py:import struct
DOWNLOADS/iotop-0.5/build/lib/iotop/data.py:import struct
DOWNLOADS/iotop-0.5/iotop/netlink.py:import struct
DOWNLOADS/iotop-0.5/iotop/genetlink.py:import struct
DOWNLOADS/iotop-0.5/iotop/data.py:import struct

Check directory existence recursively
find -type d -name "directory name to find" -print
e.g.
# find /exported -type d -name "iotop" -print
/exported/DOWNLOADS/iotop-0.5/build/lib/iotop
/exported/DOWNLOADS/iotop-0.5/iotop
 

Difference between grep, egrep and fgrep
gerp Search a Pa tern from current directory.

egrep (grep -E in linux) is extended grep where additional regular expression metacharacters have been added like +, ?, | and ().

fgrep (grep -F in linux) is fixed or fast grep and behaves as grep but does not recognise any regular expression metacharacters as being special.

No comments:

Post a Comment