Ads 468x60px

Monday, July 23, 2012

Linux: Commands (find, which, type, grep/egrep)

This will help you to understand Linux commands like find, which, type, grep/egrep

•   Find all lib files greater than 100 KB in /lib
Ans. $ find /lib -size +100k

•   Find all files which are smaller than 200 bytes
Ans. $ find /lib -size -200c

•   Find all symbolic links in /lib
Ans. $ find /lib -type l

•   Find all files which have been modified in last 24 hours
Ans. $ find /lib -mtime -1

•   Find the file “cpuinfo” and print its first lines using “head” in the same command
Ans. $ head `find / -name "cpuinfo"`

•   Find your group name and ID, and search all files which belong to your group using group name and ID
Ans. groupname: $ whoami
        groupid:   $ id-g
        $ find -group root
        $ find -gid 0

•   Find all files which have “.so” in their names using regular expressions
Ans. $ find -name "*.so"

•   Find paths of “find”, “cd”, “ifconfig” and “cp”
Ans. $ which find
        $ which cd
        $ which ifconfig
        $ which cp

•   Find all paths for “java” and “g++”
Ans. $ which -a java
        $ which -a g++

•   Find type of “man”
Ans. $ type man

•   Find all types of “java” and “g++”
Ans. $ type -a java
        $ type -a g++

•   Find the files containing string “/proc” in /etc
Ans. $ grep -lr "/proc" /etc

•   Find the files in /etc which contains the string “nameserver” at start of a line
Ans. $ egrep -lr "^nameserver" /etc

•   Find the files which contain the words “ext2” or “ext3” or “reiser”
Ans. $ egrep -lr "(ext2|ext3|reiser)" /

•   Find the files starting with the letter ‘m’ and containing string “MemFree” in /proc
Ans. $ grep "MemFree" `find /usr/bin -name "m*"`

•   Find all the files which contains “i586” in /etc and /home
Ans. $ grep -lr "i586" /etc /home

No comments:

Post a Comment