nl
stringlengths
13
387
bash
stringlengths
1
532
Give all files in the /path/to/base/dir tree read privileges
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
list all CSS files (and directories ending with “.css”) under the current directory
find . -name "*.css"
list all CSS files under the current directory
find . -type f -name "*.css"
list all the directories in the folder httpdocs
find httpdocs -type d
List all directories of the $topdir directory tree that contain a Makefile and at least one .py file
find "$topdir" -name '*.py' -printf '%h\0' | xargs -0 -I {} find {} -mindepth 1 -maxdepth 1 -name Makefile -printf '%h\n' | sort -u
list all files
find .
List all files and directories in the /home directory tree whose names are "Trash"
find /home -name Trash -exec ls -al {} \;
List all files/directories under current directory
find -ls
List all files/directories under current directory
find .
List all files/directories under current directory
find . -print
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f -exec ls -l {} \;
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f -ls
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f | xargs ls -l
List and remove all regular files named "core" under /prog that are larger than 500k
find /prog -type f -size +1000 -print -name core -exec rm {} \;
List the directory paths of all file.ext files under present working directory
find . -name "file.ext" -execdir pwd ';'
List the directory paths of all file.ext files under present working directory
find `pwd` -name "file.ext" -exec dirname {} \;
List the directory paths of all file.ext files under present working directory
find `pwd` -name file.ext |xargs -l1 dirname
list files in /u/bill that were last read from 2 to 6 minutes ago
find /u/bill -amin +2 -amin -6
List files larger than 9MB residing in the current directory and below
find . -size +9M
List regular files in current directory with read, write and execute permission for all users and also show the permissions
find . -type f -perm 777 -exec ls -l {} \;
List regular files in current directory with read, write and execute permission for all users and also show the permissions
find . -type f -perm a=rwx -exec ls -l {} \;
List the regular files of the current directory tree that contain string "texthere"
find -type f -exec grep -l "texthere" {} +
list regular file which file name end with 'cache' 'xml' or 'html' in current directory
find . -type f \( -name "*cache" -o -name "*xml" -o -name "*html" \)
Locate files not owned by any user or group
find / -path /proc -prune -o -nouser -o -nogroup
Make a copy of the entire contents of SRCFOLDER called "DESTFOLDER", if DESTFOLDER exists, the copy will be placed within it.
cp -R SRCFOLDER DESTFOLDER/
Make directories "bravo_dir" and "alpha_dir"
mkdir bravo_dir alpha_dir
Make directories to "/some/path" as needed
mkdir -p ./some/path
Measure the disk space taken up by all *.txt files in directory trees folder1 and folder2
find folder1 folder2 -iname '*.txt' -print0 | du --files0-from - -c -s | tail -1
Move all directories in the current directory tree that have been modified in the last day to "/path/to/target-dir"
find . -depth -type d -mtime 0 -exec mv -t /path/to/target-dir {} +
Move all directories in the current directory tree that have been modified in the last day to "/path/to/target-dir"
find . -type d -mtime -0 -exec mv -t /path/to/target-dir {} +
Move all directories in the current directory tree that have been modified in the last day to "/path/to/target-dir"
find . -type d -mtime -0 -print0 | xargs -0 mv -t /path/to/target-dir
Move all files in the current directory tree that match "some_pattern" to "target_location"
find . -name some_pattern -print0 | xargs -0 -I % mv % target_location
Numerically sort file "temp.txt" by the second "-" separated value of each line ordered from highest value to least value
tac temp.txt | sort -k2,2 -r -u
Print a colon-separated list of all directories from the $root directory tree, except those matching pattern ".[a-z]*"
find "$root" -name ".[a-z]*" -prune -o -type d -printf '%p:'
Print all directories under $root appending a : (colon) at the end of each path
find $root -type d -printf '%p:'
Print all files and directories in the `.' directory tree skipping SCCS directories but printing out the SCCS directory name
find . -print -name SCCS -prune
Print all the file/directory paths under current directory
find | xargs
Print the current directory tree
tree
Print the entire saved command history
history
Prints last modified file in a current folder with modification time.
find . -type f -printf '%TY-%Tm-%Td %TH:%TM: %Tz %p\n'| sort -n | tail -n1
Print the list of all files under the current directory and below
find .
Print the names of all files in the home directory and its subdirectories recursively whose MIME type is video
find ~ -type f -exec file -i {} + | grep video
Print your/dir if it's empty
find your/dir -prune -empty
Recursively change the owner of all files in "~/tmp" to "$USER"
sudo chown -R $USER ~/tmp
recursively change owner of the directory /usr/local/lib/node_modules/ to the current user
sudo chown -R $USER /usr/local/lib/node_modules
Recursively copies 'include/gtest' to '/usr/include', preserving all attributes, and copying symlinks as symlinks, without following in source files.
sudo cp -a include/gtest /usr/include
Recursively removes all files named '.svn' in a current folder, and prints messages on each action.
find . -name .svn -exec rm -v {} \;
Remove all *.txt files in the home directory tree with confirmation
find $HOME/. -name *.txt -ok rm {} \;
Remove any file containing string "GUI"
find / -type f -print0 | xargs -0 grep -liwZ GUI | xargs -0 rm -f
Report file systems disk space usage pretty formatted.
df -Ph | column -t
Save directory "../../lib" relative to the executable "gcc" to variable "libdir"
libdir=$(dirname $(dirname $(which gcc)))/lib
Search the .cs files of the current directory tree for string "content pattern"
find ./ -type f -iname "*.cs" -print0 | xargs -0 grep "content pattern"
Search the .css files in the /starting/directory tree for ".ExampleClass"
find /starting/directory -type f -name '*.css' | xargs -ti grep '\.ExampleClass' {}
Search /dev/shm and /tmp for regular files not changed in two weeks
find /dev/shm /tmp -type f -ctime +14
Search /etc for files modified within the last day
find /etc -type f -ctime -1
Search the /path directory tree for files that do not have a valid user or group
find /path -nouser -or -nogroup
Search /tmp/ for files smaller than 100 bytes
find /tmp -size -100c
Search /usr, /home, /tmp for *.jar files
find /usr /home /tmp -name "*.jar"
Search /var/tmp for files larger than 30 MB modified 31 days ago
find /tmp /var/tmp -size +30M -mtime 31 -ls
Search all .c and .h files in the current directory tree for string "e"
find . -name "*.[ch]" -exec grep --color -aHn "e" {} \;
Search the current directory recursively for directories with the execute permission set for everybody
find -type d ! -perm -111
Search the current directory tree for *.c and *.sh files
find . -type f \( -name "*.c" -o -name "*.sh" \)
Search the current directory tree for directories that can be opened by noone
find -type d ! -perm -111
Search the current directory tree for files containing "bash" in their names
find . -name "*bash*" | xargs
Search the current directory tree for files matching regular expression '.*myfile[0-9][0-9]?'
find . -regex '.*myfile[0-9][0-9]?'
Search the current directory tree for files whose name is ".note", case insensitive
find . -iname '.note' | sort -r
Search the entire system for SUID or SGID files
find / -path /proc -prune -o -type f -perm +6000 -ls
Search files "file-containing-can't" in the current directory tree for the string "can't"
find . -name "file-containing-can't" -exec grep "can't" '{}' \; -print
Search the files from the current directory tree for "foo"
find . -exec grep -l foo {} +
search for a word in all the php files in the current folder and display the matching lines. PLus at the end takes multilple files as input
find . -name \*.php -type f -exec grep -Hn '$test' {} \+
search for a word in all the regular files in the current folder without traversing the sub directories .
find -maxdepth 1 -type f | xargs grep -F 'example'
search for all the directories in the current directory and do not search in sub directories
find . -mindepth 1 -maxdepth 1 -type d
Search for files "file1" or "file9"
find . -name file1 -or -name file9
Search for files which have read and write permission for their owner, and group, but which other users can read but not write to.
find . -perm 664
Search for symlinks pointing to anywhere within /mnt/oldname/
find / -type l -lname '/mnt/oldname*'
search for text files in the directory "/home/user1" and copy them to the directory /home/backup
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents
Search for the wp-config.php file in /var/www and one level below
find /var/www/ -name wp-config.php -maxdepth 2
Search only for regular files
find -type f
Search regular files under ~/mail for string "Linux"
find ~/mail -type f | xargs grep "Linux"
Set 644 permission to all regular files under current directory
find . -type f -exec chmod 644 {} \;
Set 644 permission to all regular files under current directory
find . -type f -print0 | xargs -0 chmod 644
Set the permissions of all directories inside the current directory tree to u=rwx,g=rx,o=x
find . -type d -exec chmod u=rwx,g=rx,o=x {} \;
Set permissions to 500 for directories under the current directory
find . -type d -exec chmod 500 {} \;
Show manual page of find utility
man find
Simulate a full login
su -
split all files in directory "/dev/shm/split/" into pieces per 1000 lines
find /dev/shm/split/ -type f -exec split -l 1000 {} {} \;
split all files in directory "posns " into pieces per 10000 lines
find posns -type f -exec split -l 10000 {} \;
start from current directory, skip the directory src/emacs and all files and directories under it, and print the names of the other files found
find . -wholename './src/emacs' -prune -o -print
tar all the regular java files to myfile.tar
find . -type f -name "*.java" | xargs tar cvf myfile.tar
use find -exec with multiple commands
find . -name "*.txt" -exec echo {} \; -exec grep banana {} \;