- Resources
- Find
- Search
- Processes
- File permissions
- List files
- Symlinks
- Checking logs
- Text manipulation
- Sed
- Networking
- Space
- Miscellaneous
find dir -type fFind all files in the directoryfind dir -type dFile all directories within this directoryfind dir -name “a*.mp3” -print0Find all files/directory with name like a***.mp3find dir -type f -name “a*.txt”Find all files (recursively) with name like a***.txtfind dir -type f -print0 | xargs -0 grep -l "word"List file names with matching wordfind dir -type f -print0 | xargs -0 mv -tMove all files from dir tree into single directory
grep “word” fileAll matching lines in the filegrep -i “word” fileAll matching lines - Ignore casegrep -r “word” dirAll matching lines in (recursively) all files or directorygrep -c “word” fileCount of matching linesgrep “word” file | wc -lCount of matching linesgrep -v “word” file | wc -lCount of non-matching linesgrep -o -w “word” file | wc -wWord countgrep -l -r “word” dirList file names with matching wordfind dir -type f -print0 | xargs -0 grep -l "word"List file names with matching word
nohup program.sh > mylog.txt 2>&1 &&starts process as child process in the backgroundnohupCtrl-C or terminating session sends kill signal to all child processes,nohupcatches and ignores it>redirect output (from left/source to right/target)2error stream1output stream2>&1append all errors to output
topCheck CPU and memory consumptionkill -9 processIdkill the process with that pidkill -3 processIdfor a JVM process, will write thread dump to output streamps -ef | grep wordfind process with matching wordecho $?print output of last process
chmod fileChangechmod +x fileAdd execute permissionchmod +w fileAdd write permissionchmod +r fileAdd read permissionchmod 755 fileChange permissionchmod -R 755 dirChange permission recursivelychmod g+w fileAdd write permission at group level- Numbers: 1=x, 2=w, 3=w+x, 4=r, 5=r+x, 6=r+w, 7=r+w+x
- References: u=user, g=group, o=others, a=all
lslist files in this directoryls -ltrlist files in this directory with more details and in reverse chronological orderls -ltrasame as above + list hidden files (names starting with.)ls -ltr | grep "^l"Lists all symlinks (ls -ltrlists symlinks withlas first character of output)
- Symbolic or soft links. Pointer to a file.
ln -s /java/jdk7 jdkcreate symlink jdk which points to/java/jdk7ln -ns /java/jdk8 jdkupdate symlink jdk to point to/java/jdk8
tail -f logfileoutput appended data as file grows (f=follow)less +F logfileopen file, and output appended data as file grows
head filedisplay first 10 lineshead -20 filedisplay first 20 linestail filedisplay last 10 linestail -5 filedisplay last 5 lineshead -20 file | tail -1display 20th linecut -f3 filedisplay 3rd field for each line, tab as separatorcut -d',' -f3 filedisplay 3rd field for each line,,as separatorcut -c3-6 filedisplay characters from 3rd to 6th position for each linecut -c7- filedisplay characters from 7th to end of each line
sed s/unix/linux filereplace first occurrence of "unix with "linux"sed s/unix/linux/3 filereplace 3rd occurrencesed s/unix/linux/g filereplace all occurrencessed s/unix/linux/3g filereplace all occurrences starting from 3rd onesed -i '1 d' filedelete header of filesed -i '$ d' filedelete footer of filesed –n '10 p' fileprint 10th line of the file
ping hostnameortelnet hostname portcheck if remote host is alivescp /dir/file user@hostname:/targetdir/filecopy file to different hostnetstat -a | grep "port"check host connected to machine's port
df -hspace in current drive (-his human readable format)du -h .sizes of all files in current directorydu -sh .sizes of current directorydu /bin/* | sort -nsort all files based on size (asc)
lsof filelist processes using the filerev filereverses the text in each lineecho "string" | revreverses the stringsort filesorts file lines alphabeticallysort -n filesorts file lines numericallyuniq filefilter out adjacent duplicate lines and printuniq -c fileprint with count at the begining of each line of outputuniq -d fileprint only duplicates