nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all files under /home/username/public_html/modules and set their permission to 640
find /home/username/public_html/modules -type f -exec chmod 640 {} +
Page through the contents of yourFile, adding a $ at the end of each line and replacing tab characters by ^I.
cat -vet file | less
delete all files in the home directory which ahve the name core in them
find ~/ -name 'core*' -exec rm {} \;
Search the regular files of the current directory tree for string "foo"
find . -type f -exec grep "foo" '{}' \;
Replace all occurrences of 'previousword' with 'newword' in all regular files with '.cpp' extension under '/home/www' directory tree and modify them in-place
find /home/www -type f -name '*.cpp' -exec sed -i 's/previousword/newword/g' '{}' \;
Find all Name* files under ../../$name-module and rename them by replacing 'Name' with $Name in their names
find ../../$name-module -name 'Name*' -type f -exec bash -c "mv \"\$1\" \"\${1/Name/$Name}\"" -- {} \;
Find all directories named "0" in the current directory tree and create a tar archive of their RS* subdirectories
find . -type d -name "0" -execdir tar -cvf filename.tar RS* \;
Recursively finds all 'STATUS.txt' files containing text 'OPEN' and prints containing folder of them.
fgrep --include='STATUS.txt' -rl 'OPEN' | xargs -L 1 dirname
Merge content of decompressed files "$part0", "$part1", and so on
sort -m <(zcat $part0 | sort) <(zcat $part1 | sort) ...
Perform case-insensitive search for file `TeSt123.txt' on the system
find / -iname TeSt123.txt
Find all files under /home/username/public_html/sites/all/themes and set their permission to 640
find /home/username/public_html/sites/all/themes -type f -exec chmod 640 {} +
Delete all 1US* (case insensitive) files under current directory
find . -iname "1US*" -exec rm {} \;
read all history lines not already read from the history file
history -n
find md5sum of string 'hi'
echo -n hi | md5
Rename all files and directories under current directory tree by converting the names to small letters without descending into 'CVS' directory
find . -name CVS -prune -o -exec mv '{}' `echo {} | tr '[A-Z]' '[a-z]'` \; -print
Find all the files which are accessed 50 days back
find / -atime 50
Change permissions to 644 for all directories under and below /path/to/someDirectory/
find /path/to/someDirectory -type d -print0 | xargs -0 sudo chmod 755
Show all files in user's home directory that have read, write and execute permissions set for user, group and others.
find ~ -perm 777
Read a line from standard input into variable "message" with prompt "Please Enter a Message: " followed by a newline
read -p "Please Enter a Message: `echo $'\n> '`" message
Delete in the background all files in /var/tmp/stuff1 and below that have not been modified in over 90 days
find /var/tmp/stuff1 -mtime +90 -delete &
Find all files on the system whose names are 'composer.json'
find / -name composer.json
Find all *.py files under and below the current directory and search them for "xrange"
find . -name '*.py' -exec grep --color 'xrange' {} +
find all the files in current folder which have spaces and save the long listing of these files to log file before deleting them
find . -name "filename including space" -print0 | xargs -0 -I '{}' sh -c 'ls -aldF {} >> log.txt; rm -rdf {}'
display all the empty files in the entire file system
find / -size 0 -print
Save the user name in upper case of the current user in variable "v"
v=$
Look for *.jpg files on the system
find / -name “*.jpg”
Prints last modified file in a current folder with modification time.
find . -type f | sed 's/.*/"&"/' | xargs ls -E | awk '{ print $6," ",$7 }' | sort | tail -1
SSH using parameters in $@ in master mode in the background without executing any commands and set the ControlPath to "$MASTERSOCK"
ssh -o ControlPath="$MASTERSOCK" -MNf "$@"
Set permissions of command "node" to 755
sudo chmod 755 $(which node)
Search the home directory tree for video files
find ~ -type f -regex '.*\.\(mkv\|mp4\|wmv\|flv\|webm\|mov\)'
Print "Shared Memory" if shared memory mounted at /tmp or print "Not Shared Memory" otherwise.
df /tmp | grep -q tmpfs && echo "Shared Memory" || echo "Not Shared Memory"
Print the list of files and directories of the /etc directory
find /etc ! -name /etc
set alias "s" for command 'it=$($)'
alias s='it=$($)'
search for all the files in the folder /data/images which have been modified after /tmp/start and before /tmp/end and save the output list to output.txt
find /data/images -type f -newer /tmp/start -not -newer /tmp/end > output.txt
Format the output of "..." as a tab separated table
... | column -s$'\t' -t
Archive "/home/path" to "path" on host "server" showing progress and statistics and remove files in the destination not found in the source
rsync -a --stats --progress --delete /home/path server:path
Constantly write "y" to backingfile as a background process
yes > backingfile &
Read a line from standard input into the first argument using an interactive shell with prompt "> "
read -e -p '> ' $1
Print all unique file paths under "dir1" compared to "dir2"
comm -23 < < | sed 's/^\//dir1/'
Find files with size more than 200557600B and which are more than 2 days old under ${userdir}/${i}/incoming directory and remove them
find ${userdir}/${i}/incoming -mtime +2 -type f -size +200557600c -exec rm {} \;
recursively change user of the direct public_html and all files into it to user owner
chown -R owner:owner public_html
find all the mp3 files in the entire file system whose size is bigger than 10MB
find / -type f -name *.mp3 -size +10M -exec rm {} \;
Search for 'pattern_to_search' in all regular files with '.txt' extension under '/directory/containing/files' and show the matched lines along with filenames
find /directory/containing/files -type f -name "*.txt" -exec grep -H 'pattern_to_search' {} +
search for files named "WSFY321.c" in a case-insensitive manner
find . -iname "WSFY321.c"
change the permissions of all the directories to 775 in the current folder
find . -type d -exec chmod 775 {} \;
Print git branch currently checked out in a working directory.
git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
Answer "y" to all "Are you sure?" prompts from command "cp * /tmp"
yes | cp * /tmp
Archive directory specified by variable "myFolder" to current directory.
rsync -av $myFolder .
Find all directories under $1/.hg and set their SGID bit
find "$1"/.hg -type d -print0 | xargs chmod g+s
Save a line of 100 random characters either "." or " " in variable "foo"
foo=$(cat /dev/urandom | tr -dc '. ' | fold -w 100 | head -1)
Find all Makefile's in the current directory tree and look for line 235 in each of them
find . -name Makefile -print0 | xargs -0 grep -nH $ | grep :235:
print the names of all of the unstripped binaries in the /usr/local directory tree. Builtin tests avoid running file on files that are not regular files or are not executable
find /usr/local -type f -perm /a=x | xargs file | grep 'not stripped' | cut -d: -f1
Find all regular files recursively in the current directory
find . -type f
Copies ${FILE} to COLLECT folder with unique name formatted like 'job_XXXXXXXXX'.
cp "${FILE}" "COLLECT/$"
Check if current shell is running within a 'screen' process.
pstree --show-parents -p $$ | head -n 1 | sed 's/\+.*/\1/' | wc -l
Remove all .php files in the /var/www/ directory
find /var/www/*.php -type f -exec rm {} \;
Find all files in $dir directory (non-recursive) and count them
find "$dir" -maxdepth 1 -type f | wc -l
delete all the files in the current folder which do not belong to any user
find / -nouser -exec rm {}\;
List all files in a current folder, separating names with semicolon
ls -1b | tr '\n' ';'
Find all files named "file.ext" in the current directory tree and print the path names of the directories they are in
find $PWD -name "file.ext" -exec sh -c 'echo $' ';'
Search for files/directories with a case insensitive .txt extension in entire file system
find / -iname '*.txt'
Find all files/directories under '/usr' directory tree that have been modified exactly 5 minutes ago
find /usr -mmin 5
Find all files/directories under current directory that match the case insensitive regex ./\.* and show several lines of output from the beginning
find . -iregex './\.*' | head
Show all files in /etc that are owned by root have been modified within the last minute
find /etc/ -user root -mtime 1
Go to directory specified by variable "somedir", but replacing leading ~ character by actual home directory.
cd $
change to a directory and search for a file in that directory
cd /nfs//office/ && find . -name '.user.log'
Output the file name "file.txt' from the path "some/unknown/amount/of/sub/folder/file.txt"
basename "some/unknown/amount/of/sub/folder/file.txt"
Remove all regular files under '/var/log/remote' directory tree that have not been modified in the last 14 days where day count starts from today
find /var/log/remote/ -daystart -mtime +14 -type f -exec rm {} \;
Find all broken symlinks under current directory
find -type l -xtype l
Follows symbolic link $BASH_SOURCE, and prints path to its target.
$(dirname $(readlink -f $BASH_SOURCE))
Find all *.* files under current directory
find . -type f -a -name '*.*'
List all nfs mounts
mount -l -t nfs4
Print all user names and terminals of users who are logged in
who | awk '{ print $1, $2 }'
Find all files/directories with 777 permission under '/apps/audit' and strip write permission for 'other' from them
find /apps/audit -perm -7 -print | xargs chmod o‑w
extract "filename.tar.xz" with verbose output
$ tar xvfJ filename.tar.xz
Show all running processes with a name matching "postgres"
ps -ef | grep postgres
Use the octal form to find and print detailed information about all regular files in your home directory and below that have only the group permission set.
find . -perm 040 -type f -exec ls -l {} \;
Find all files on the system whose names are 'autoload.php'
find / -name autoload.php
Print unique lines in "file1" compared to "file2" in the order they appear
comm -23 < <|grep -f - file1
search for files in current folder using name patterns
find . -name "S1A*1S*SAFE"
Print git branch currently checked out in a working directory.
git branch | grep "*" | cut -d ' ' -f 2
download contents of a website "http://example.com/"
curl http://example.com/
search for all the files in the current directory which have been modified in the last 24 hours.
find . -mtime -1
search for all the files ending with "fits" in the folder "/store/01"
find /store/01 -name "*.fits"
Find every file/directory under /var/spool that was modified more than 60 days ago.
find /var/spool -mtime +60
Lists all directories in a current folder.
ls -d */
Search all files called "abc" that reside in the current directory tree for string "xyz"
find . -name abc | xargs grep xyz
Make directory "dir1"
mkdir dir1
change the owner of all the files in the file system which belong to the user with the uid 999
find / -user 999 -exec chown NEWUSER {} \;
Save the first 3 lines output by 'yes' to 'file', and log the rest through 'more' which simply waits for user interaction at each page.
yes | awk 'FNR<4 {print >>"file"; close} 1' | more
Find files and directories with the name RAID but don't traverse a particular directory
find . -name RAID -prune -o -print
Find all file.ext files/directories under present working directory and print . for each of them
find `pwd` -name "file.ext" -exec echo $ \;
Find all files in the current directory and below with extension .php and replace "php" with "html" in their names
find ./ -type f -name "*.php" | xargs -r rename "s/php/html/"
find all files in current folder using name patterns
find . -iregex ".*packet.*"
Find all files/directories under current directory tree with inode number 211028 and move them to 'newname.dir'
find . -inum 211028 -exec mv {} newname.dir \;
Find all files under current directory and set read permission for group and other for these files
find . -type f -print0 | xargs -0 chmod go+r
Remove trailing white spaces from all files under dir directory and keep backups of the originals
find dir -type f -print0 | xargs -0 sed -i .bak -E "s/[[:space:]]*$//"
search for the directory "mysql" in the /etc folder
find /etc -name mysql -type d
Split a file "file.tar.gz" into pieces with size 1024 MB
split -b 1024m file.tar.gz
Remove all *.bak and *.backup files that were accessed last time more than 30 days ago
find . \ -type f -atime +30 -exec rm '{}' ';'