nl
stringlengths
13
387
bash
stringlengths
1
532
Print the list of .txt files under and below the current directory
find . -name '*.txt' -print0|xargs -0 -n 1 echo
Print the list of all regular files in the current directory and below
find . -type f
Prints long recursive listing of all content of a root folder, saving output to 'output.file'.
ls -lR / | tee output.file
Print out the names of all directories in mydir recursively
find mydir -type d
Print the sorted and unique parent directory paths appended with : of all the files that are executable by owner under ~/code directory without descending into hidden directories
find ~/code -name '.*' -prune -o -type f -a -perm /u+x -printf ':%h\n' | sort | uniq | tr -d '\n'
Print which files differ in "dir_one" and "dir_two" recursively and sort the output
diff -qr dir_one dir_two | sort
Recursively change the owner and group of all files in "public_html" to "owner"
chown -R owner:owner public_html
recursively change owner and group of the directory /vol/html and all files into it to user ec2-user and group apache
sudo chown -R ec2-user:apache /vol/html
Recursively change the owner of all files in "/home/test" to "test"
sudo chown -R test /home/test
recursively change owner of the directory /usr/lib/node_modules/ to the current user
sudo chown -R $(whoami) /usr/lib/node_modules/
Recursively change ownership of "/usr/local/lib" to the current user
sudo chown -R `whoami` /usr/local/lib
Recursively change the ownership of all files in "/Users/xxx/Library/Developer/Xcode/Templates" to "xxx"
sudo chown -R xxx /Users/xxx/Library/Developer/Xcode/Templates
Recursively delete all files/folders named '.svn' in a current folder.
find . -name .svn -delete
remove all "Foo*" files under current dir
find . -type f -name "Foo*" -exec rm {} \;
Remove all *.log files from the current directory tree
find -name '*.log' -delete
Remove all *.log files from the current directory tree
find ./ -name '*.log' -print0 | xargs -0 rm
Remove all *.log files from the current directory tree
find ./ -name '*.log' | xargs rm
remove all core files in the file system
find / -name "*.core" -print -exec rm {} \;
remove all core files in the file system
find / -name "*.core" | xargs rm
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name "vmware-*.log" -exec rm '{}' \;
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name vmware-*.log -delete
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name vmware-*.log | xargs rm
remove all subdirectories named "CVS" under current dir
find . -type d -name CVS -exec rm -r {} \;
Remove with prompting all files that have not been accessed in over 100 days
find /mydir -atime +100 -ok rm {} \;
Rename all directories under current directory by replacing all occurrences of 'Foo' (case insensitive) with 'Bar' in their names
find . -type d -iname '*foo*' -depth -exec rename 's@Foo@Bar@gi' {} +
Replace "inputfile" with a sorted unique list of its contents
sort inputfile | uniq | sort -o inputfile
Report file system containing path to the current working directory disk usage in kilobytes.
df -k .
Report file systems disk usage, elide all entries insignificant to available space, and produce a grand total.
df --total
Report total size of the root filesystem disk usage in powers of 1000.
df -H --total /
Return 0 if file system is mounted on '/full/path'
df /full/path | grep -q /full/path
Save the absolute path of the directory of the current script to variable "DIR"
DIR=$(dirname "$(readlink -f \"$0\")")
Scan every file in /etc for IPV4 addresses while trying to elminate false positives.
find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' | grep '^[^.][^.]*\.[^.][^.]*\.[^.][^.]*\.[^.][^.]*$'
Search the /myfiles directory tree for files last accessed more than 30 days ago
find /myfiles -atime +30
Search /usr/bin for regular files that have been modified within the last 10 days
find /usr/bin -type f -mtime -10
Search all files under and below /etc for IP addresses
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
Search all regular files in the current directory for "example"
find -maxdepth 1 -type f | xargs grep -F 'example'
Search all the regular files in the current directory for "example"
find -maxdepth 1 -type f | xargs grep -F 'example'
Search the current directory, except the subdirectory tree ".svn", for files whose name is "foo.cpp"
find . -name 'foo.cpp' '!' -path '.svn'
Search the current directory tree for all files matching pattern "*.rb"
find . -name "*.rb"
Search the current directory tree for files larger than 10MB but smaller than 50MB
find . -size +10M -size -50M -print
Search the current directory tree for files modified less than 5 days ago
find . -mtime -5
Search the current directory tree recursively for the regular file named "myfile" ignoring "work" and "home" directories
find . \( -name work -o -name home \) -prune -o -name myfile -type f -print
search for a files "cart1" in the folder junk which is in home folder and move the folder to ~/junk/A.
find ~/junk -name 'cart1' -exec mv {} ~/junk/A \;
search for a regular/normal file myfile in the folder "/home/weedly"
find /home/weedly -name myfile -type f -print
search for all the c files in the current folder
find . -name \*.c -print
search for all the files in the current folder which start with "my"
find . -name 'my*'
search for all the files with the name "dummy" in the current folder
find -type f -name dummy
search for all the regular/normal files in the current folder which start with "my"
find . -name 'my*' -type f
search for the file "foo.txt" in the entire file system
find / -name foo.txt
search for the file "myfile" in the current folder and display all errors apart from permission denied error
find . -name myfile |& grep -v 'Permission denied'
search for files in the current folder using name patterns
find . -name '[mM][yY][fF][iI][lL][eE]*'
search for files which are writable by either their owner or their group
find . -perm /220
search for files which are writable by either their owner or their group
find . -perm /u+w,g+w
search for files which are writable by either their owner or their group
find . -perm /u=w,g=w
Search for files whose size is between 100 kilobytes and 500 kilobytes
find . -size +100k -a -size -500k
Search for the pattern 'search string' in all the files in the ''/tmp folder and display the matched lines along with the file names
find /tmp -type f -exec grep 'search string' '{}' /dev/null \+
Search for regular file foo ignoring case
find . -iname foo -type f
Search for regular files of the grooup 'users' in the file system
find / -type f -group users
search for word linux in all the regular/normal files in the folder mail.
find ~/mail -type f | xargs grep "Linux"
Search the local subdirectory tree of the current working directory and the /tmp directory tree for directories named mydir
find local /tmp -name mydir -type d -print
Search the regular files of the current directory tree for string "foo"
find ./ -type f | xargs grep "foo"
Search through the /usr/local directory for files that end with the extension .html, and print the file locations.
find /usr/local -name "*.html" -type f
Searches through the htdocs and cgi-bin directories for files that end with the extension .cgi. When these files are found, their permission is changed to mode 755 (rwxr-xr-x).
find htdocs cgi-bin -name "*.cgi" -type f -exec chmod 755 {} \;
Show a listing of files not modified in over 20 days or not accessed in over 40 days
find /mydir \(-mtime +20 -o -atime +40\) -exec ls -l {} \;
show all the files in current directory
find .
show all the mp3 files in the folder /home
find /home -type f -name '*.mp3'
Show the list of all files on the system whose names do not end in ".c"
find / \! -name "*.c" -print
Split "file.tar.gz" into files of size 1024 MB
split -b 1024m file.tar.gz
split content of the files *.txt beginning with 1001st line into pieces per 1000 lines
cat *.txt | tail -n +1001 | split --lines=1000
verbosely create intermediate directoriy tmp as required and directory boostinst
mkdir -pv /tmp/boostinst
View manual page of the find command
man find
View manual page of find utility
man find
change group of the file /tmp/php_session to group daemon
chown -R :daemon /tmp/php_session
Change mode of all files ending with ".php" under the current folder to 755 and write the output to the console and "logfile.txt" file
find . -name '*.php' -exec chmod 755 {} \; | tee logfile.txt
change owner and group of the file dir1 to user root and group specialusers
chown root:specialusers dir1
change the owner of the files which belong to the group 1000 to username and modify only the symbolic link not the originally pointed file
find -gid 1000 -exec chown -h :username {} \;
Change permissions for all PHP files under the current directory tree to 755 and print the number of files changed
find . -name "*.php" -exec chmod 755 {} + -printf '.' | wc -c
Change permissions for all PHP files under the current directory tree to 755 and print the number of files changed
find . -name "*.php" -exec chmod 755 {} \; -exec /bin/echo {} \; | wc -l
change the permissions of all regular/normal files in the file system
chmod 640 `find ./ -type f -print`
Change the permissions of the current directory and all its subdirectories to 755.
find . -type d -exec chmod 755 {} \;
Check if $path_in_question is mount point of filesystem
df $path_in_question | grep " $path_in_question$"
Compresses all '*.xml' files under current directory with 'bzip2' utility.
find -name \*.xml -print0 | xargs -0 -n 1 -P 3 bzip2
compress all the non-compressed files in the current directory.
find . \! -name "*.Z" -exec compress -f {} \;
Copies all files under the current directory but ones with '*/not-from-here/*' in path to the '/dest/' directory.
find . -type f -not -iname '*/not-from-here/*' -exec cp '{}' '/dest/{}' ';'
Counts lines in each *.php file.
wc -l `tree -if --noreport | grep -e'\.php$'`
Count the number of regular files in the current directory tree
find . -type f | wc -l
create a md5sum for all the instances of the file MyCProgram.c in current folder
find -iname "MyCProgram.c" -exec md5sum {} \;
create directory /etc/cron.5minute
mkdir /etc/cron.5minute
create directory dirname with permissions 777
mkdir -m 777 dirname
create directories foo and bar
mkdir foo bar
create directories mnt and point
mkdir mnt point
Create intermediate directories "b and "c" as required and directory "c"
mkdir -p a/b/c
Create intermediate directories "full", "path" as required and directory "to"
mkdir -p `dirname /full/path/to/file.txt`
Create intermediate directories as required and directory project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat/a}
Delete all empty directories under test directory
find test -depth -type d -empty -delete
Delete all files/directories named 'FILE-TO-FIND' under current directory tree
find . -name "FILE-TO-FIND" -exec rm -rf {} \;
Delete all files in the current user's home directory and its sub-directories that have not been accessed for more than 100 days.
find ~ -atime +100 -delete
Delete empty directories
find . -type d -empty -delete
Delete file with inode number 314167125
find . -type f -inum 314167125 -delete
Delete files with inode number 782263 under current directory
find . -inum 782263 -exec rm -i {} \;