nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Save the absolute path of the directory of the current script to variable "DIR"
DIR=$(dirname "$(readlink -f \"$0\")")
Find all files in the current directory tree whose names are ".DS_STORE" and delete them
find . -name ".DS_STORE" -delete
delete all the files in the current folder which have been modified in the last 14*24 hours
find . -mtime -14 -print|xargs -i rm \;
Find all broken symlinks under /path/to/search directory
find /path/to/search -type l -xtype l
Make a list of all files in the current directory tree, except *.png and *.class, and view it in the vim editor
find . | grep -E -v '\.png$|\.class$' | vim -
Unsets 'history' shell option.
shopt -u -o history
Finds strings with text "text" in all files named "string to be searched" recursively in a current folder.
find . -name "string to be searched" -exec grep "text" "{}" \;
List all files under and below the directory given as variable $ARCH1
find $ARCH1 -ls
Find *.scm files recursively in the current directory
find . -name '*.scm'
Recursively search for "string here" and write the output to the console followed by the number of matched lines
grep -r "string here" * | tee >
Search all files in the current directory tree whose names end in "1" for string "1"
find . -name "*1" -exec grep "1" {} \;
Searches the manual pages with descriptions in section 3, that name begins with lowercase letter.
apropos -s 3 . | grep ^[a-z]
Find all .bak files starting from the current directory and delete them
find . -iname "*.bak" -type f -print | xargs /bin/rm -f
Search /dev/shm and /tmp for regular files not changed in two weeks
find /dev/shm /tmp -type f -ctime +14
Format space separated fields in "filename" as a table
column -t -s' ' filename
Find all your jsp's, map them to your localhost webserver, and invoke a wget on them
find -name \*.jsp | sed 's/^/http:\/\/127.0.0.1/server/g' | xargs -n 1 wget
searches through the root filesystem for the file named Chapter1, and prints the location
find / -name Chapter1 -type f -print
display long listing of all the regular hidden files in the folder Musica
find Música/* -type f -name ".*" -exec ls -l {} \;
Save directory "../../lib" relative to the executable "gcc" to variable "libdir"
libdir=$(dirname $(dirname $))/lib
Search the current directory tree for files and directories whose names begin with "pro"
find . -name pro\*
Starts new tmux session, assuming the terminal supports 256 colours.
tmux -2
Search the `images' directory tree for regular files
find images/ -type f
Create intermediate directories as required
mkdir -p $2
display all the regular/normal files in a folder
find $FILES_PATH -type f
Remove the files or directories 'bin/node', 'bin/node-waf', 'include/node', 'lib/node', 'lib/pkgconfig/nodejs.pc' and 'share/man/man1/node.1'
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Remove all *.mp3 files in tmp directory but not in it's subdirectories
find tmp -maxdepth 1 -name '*.mp3' -maxdepth 1 | xargs -n1 rm
Find all files/directories under current directory with a Depth-First search
find dir -depth
Write output of "foo" to standard output and to "output.file"
foo | tee output.file
Set permissions to 660 for all regular files in the current directory tree
find . -type f -exec chmod 0660 {} +
use find command to search for .png and .jpg files
find ./ -type f \
Find all *.ogg files/directories under your home directory that are not greater than 20MB in size
find $HOME -iname '*.ogg' ! -size +20M
find all the instances of the file "foo.txt" in the current folder and move them to another folder
find . -name foo.txt 1> tmpfile && mv `cat tmpfile` path/to/some/dir && rm tmpfile
Print the 5th space separated fields in "file" as a comma separated list
cut -d' ' -f5 file | paste -d',' -s
Remove all regular files under and below directory "$DIR" that were last accessed more than 5 days ago
find "$DIR" -type f -atime +5 -exec rm {} \;
search all mp3 files in the folder "/home/you" which have been modified yesterday (from the start of day 00:00 to 23:59)
find /home/you -iname "*.mp3" -daystart -type f -mtime 1
Remount "yaffs2" filesystem "/dev/block/mtdblk4" to "/system" as read only
mount -o ro,remount -t yaffs2 /dev/block/mtdblk4 /system
Find all directories under current directory excluding directories (along with their contents) that start with a . (dot) in their names
find . -type d -a ! -name '.?*' -o -name '.?*' -a ! -prune
Decompress and sort "$part0" and "$part1" of files in different processes
sort -m < <
Print '-exec is an action so an implicit -print is not applied' for every file/directory found by the name 'file' under current directory tree
find -name file -exec echo '-exec is an action so an implicit -print is not applied' \;
Display the content of YourFile.txt, waiting for user input at each page.
more YourFile.txt
Search for files in your home directory which have been modified in the last twenty-four hours.
find $HOME -mtime 0
List all SGID and SUID files in entire file system
find / -type f \( -perm -4000 -o -perm -2000 \) -ls
Find all files/drectories under '/u/bill' directory tree that have been accessed in the last 2 to 6 minutes
find /u/bill -amin +2 -amin -6
Remove all files with the .c extension in the current directory tree
find . -name "*.c" -print0 | xargs -0 rm -rf
Search all .c files from the current directory tree for "keyword", ignoring the case
find . -name "*.c" -exec grep -i "keyword" {} ";"
Search for the case insensitive regex 'STRING_TO_SEARCH_FOR' in all files under current directory
find . -type f -exec grep -n -i STRING_TO_SEARCH_FOR /dev/null {} \;
Recursively finds last 5 modified files in a directory
find . -type f -ls 2>/dev/null | sort -M -k8,10 | head -n5
force delete all the temp files which are of size 0 bytes and which have not been accessed in the last 10 days
find /tmp -size 0 -atime +10 -exec rm -f {} \;
display all file in the home folder except ".c" files
find $HOME \! -iname "*.c" print
Find all files/directories under current directory tree that are owned by 'root'
find . -uid 0 -print
reverse both words and lines in file
tac filename | awk '{for (i=NF; i>1; i--) printf("%s ",$i); printf("%s\n",$1)}'
Updates all software in a system, skipping packages that have a failed dependencies.
sudo yum update --skip-broken
Find only directories
find . -type d
List all zero-length files
find . -empty -exec ls {} \;
Copy all files with name pattern $j.sh (case insensitive) under '/tmp/2' directory tree to $i directory
find "/tmp/2/" -iname "$j.sh" -exec cp {} "$i" \;
Removes 55, adds a 10-digit line number, and rearranges the date for each line in "input"
nl -nrz -w10 -s\; input | sed -r 's/55//; s/--/\3\2\1/'
find files with pattern` '*.h' and print comparison between file and /tmp/master directory
find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'
find all normal/regular files in the entire file system having the word "filename" in their name.
find / -type f -iname "filename"
Find all *.txt (case insensitive) files of user root under / directory and show a few lines of output from the beginning
find / -user root -iname "*.txt" | head
show all files in the current directory and all subdirectories
find .
find all files starting with capital letter in the current folder
find . — name "[A‑Z]*" — print
Find symbolic links in lpi104-6 and research/lpi104-6 to files whose pathnames end in "file1"
find lpi104-6 research/lpi104-6 -lname "*file1"
Find files that were modified less than 7 days ago and archive them
find . -type f -mtime -7 | xargs tar -cvf `date '+%d%m%Y'_archive.tar`
Remove all .mpg files in the /home/luser directory tree
find /home/luser -type f -name '*.mpg' -exec rm -f {} \;
Copies file 'file1' to each of directories 'dir1', 'dir2', 'dir3'.
echo dir1 dir2 dir3 | xargs -n 1 cp file1
Find all *.java files in the current directory tree
find . -name \*.java
Recursively finds files like '*.js', and filters out files with 'excludeddir' in path.
find . -name '*.js' | grep -v excludeddir
Remove a leading "machine" from the system host name and save the result to variable "machnum"
machnum=$
Page through extended information about all PCI devices on system.
lspci -v -v | less
Change user to "amzadm" and group to "root" of "/usr/bin/aws"
chown amzadm.root /usr/bin/aws
Search the current directory tree for regular files omitting directory `omit-directory'
find . \ -print
Extract protocol part from URL.
echo "$url" | cut -d':' -f1
Send SIGKILL signal to all processes whose command matches "csp_build"
kill -9 `pgrep -f cps_build`
search for all the non-hidden files in the current directory and do not search in the subfolders and dispaly their name and size.
find . -maxdepth 1 -name '[!.]*' -printf 'Name: %16f Size: %6s\n'
Change permissions to 755 recursively only for directories
find . -type d -exec chmod 755 {} \;
Archive all filepattern-*2009* files/directories under data/ into 2009.tar
find data -xdev -name "filepattern-*2009*" -print0 | tar --null --no-recursion -uf 2009.tar --files-from -
Display the named characters in "line1\r\nline2"
echo -e "line1\r\nline2" | od -a
find all the files which have been accessed after modifying the file /etc/hosts
find -anewer /etc/hosts
Check whether current terminal is opened in a screen session.
pstree --show-parents -p $$ | head -n 1 | sed 's/\(.*\)+.*/\1/' | grep screen | wc -l
Delete every second line from output of "seq 10"
seq 10 | sed '0~2d'
Brings down network interface eth0.
ifconfig eth0 down
find for xml files in current folder using regular expressions
find ./ -regex "cmn-.*[\x4e00-\x9fa5]*\.xml"
list all processes with its PIDs
jobs -l
Print content of 'file' file reverted characterwise
rev file
Counts the number of lines in each *.java file in a git repository.
git ls-files | grep "\.java$" | xargs wc -l
Search all files in the current directory tree whose names end in "1" for string "1"
find . -name "*1" -exec grep "1" {} \;
Make directories to "/tmp/boostinst" as needed and print a message for each created directory
mkdir -pv /tmp/boostinst
Sort "file" using a buffer with a size 50% of main memory
sort -S 50% file
Find root's Ruby files accessed in the last two minutes
find /apps/ -user root -type f -amin -2 -name *.rb
Number each line in "foobar" as right-justified zero padded to a width of 9
nl -nrz -w9 foobar
find all the files in the entire file system excluding the folder proc, which do not belong to any user or any group
find / -path /proc -prune -o -nouser -o -nogroup
Recursively archive "test/a/" to "test/dest" excluding "test/a/b/c/d"
rsync -nvraL test/a/ test/dest --exclude=/b/c/d
Display a long listing of all regular files with 0777 permission under current directory tree
find . -perm 0777 -type f -exec ls -l {} \;
Display a long listing of all the regular files owned by the user 'bluher' in the entire filesystem
find / -type f -user bluher -exec ls -ls {} \;
Find all files/directories that do not belong to any user under '/home' directory tree
find /home -nouser -print
Search the current directory recursively for the largest files
find . -type f -printf '%20s %p\n' | sort -n | cut -b22- | tr '\n' '\000' | xargs -0 ls -laSr
Find all the files which are modified more than 50 days back and less than 100 days
find / -mtime +50 –mtime -100
Installs 'glibc' package.
sudo yum install glibc
find all the files in the current folder and search for the word "vps admin" in them.
find . -exec grep -i "vds admin" {} \;
search for all the regular/normal mp3 files in the file system and move them to the folder /mnt/mp3
find / -iname "*.mp3" -type f -print0 | xargs -0 -I '{}' /bin/mv "{}" /mnt/mp3/