nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
From another terminal, detach process $PID from its terminal and run it in the background.
kill -20 $PID; kill -18 $PID
Change directory to the user's home directory
cd
Recursively removes all files with name like "*.war" in /home/ubuntu/wars folder.
find /home/ubuntu/wars -type f -name "*.war" -exec rm {} \\;
List the commands in /usr/bin, pausing for user input after each page.
more <
Delete all directories in the /myDir directory tree
find /myDir -type d -delete
ssh into "hostname" as user "buck"
ssh -l buck hostname
List the file under the current directory that has the oldest modification time
find . -type f -ls | sort +7 | head -1
Search for 'some string' in all *js files under current directory and show the matched lines with line numbers
find . -name '*js' | grep -n 'some string'
Make directories and parent directories as needed of "$1" with "\r" removed
mkdir -p $
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`
Write "hello world" to the console and print number of bytes, symbols and strings in provided input.
echo "hello world" | tee >(wc)
Count the number of areas that differ in "file1" and "file2" with 0 lines of unified context
diff -U 0 file1 file2 | grep ^@ | wc -l
Sets shell options 'globstar', 'dotglob' and 'nullglob'.
shopt -s globstar nullglob dotglob
Create a symbolic link relative to link location named "$dest_dir/$orig_name" to "$orig_dest"
ln -r -s "$orig_dest" "$dest_dir/$orig_name"
search for text files in the current folder which do not have write access to others
find . -type f \
display all the files in the current folder which have been modified in the last 24 hours excluding all directories
find . \( -type d ! -name . -prune \) -o \( -mtime -1 -print \)
Recursively print all files and directories in the directory tree "$absolute/path/of/your/dir"
tree $absolute/path/of/your/dir
Gets state of shell option 'dotglob' and saves it in 'rest_cmd' variable.
rest_cmd=$(shopt -p dotglob)
create directory /tmp/foo
mkdir /tmp/foo
Make directories in "/TARGET_FOLDER_ROOT/" for each ".mov" file in the current directory tree
find . -type f -iname \*.mov -printf '%h\n' | sort | uniq | xargs -n 1 -d '\n' -I '{}' mkdir -vp "/TARGET_FOLDER_ROOT/{}"
Change permissions to 644 for all regular files under the /path/to/dir/ tree unless these permissions are already set
find /path/to/dir/ -type f ! -perm 0644 -print0 | xargs -0 chmod 644
Delete all regular files with '.cache' extension that were accessed more than 30 days ago under $HOME/Library/Safari/Icons directory tree
find $HOME/Library/Safari/Icons -type f -atime +30 -name "*.cache" -print -delete
Removes empty folder 'edi' and 'edw'.
rmdir edi edw
Write list of files present only in dir1 to file "difference1.txt".
diff -r dir1 dir2 | grep 'Only in' | grep dir1 | awk '{print $4}' > difference1.txt
Update timestamps of all files and directories under directory /path/to/dir.
find /path/to/dir -print0 | xargs -0 touch
Search the current directory tree for all image files
find . -type f -regex ".*\.\"
Print "y" for each line in "file2.txt" found in "file1.txt" and a blank newline otherwise
comm -2 file1.txt file2.txt | awk -F'\t' '{print }'
Search the current directory tree for files named "accepted_hits.bam"
find `pwd` -name "accepted_hits.bam"
Convert the string "$myArray" into a bash array using ";" delimiters
IFS=';' read -a myArray <<< "$myArray"
Show the list of directories in the /mnt/raid directory tree
find /mnt/raid -type d -print
Search the /root directory recursively for the regular file named "myfile" ignoring /root/work/
find /root/ -path '/root/work' -prune -o -name myfile -type f -print
Enables shell option 'expand_aliases'.
shopt -s expand_aliases
Remove files that are greater than 1MB in size under <directory>
find <directory> -type f -size +1M -delete
Print the sorted uniqe list of folders in compressed archive nginx-1.0.0.tar.gz
tar tf nginx-1.0.0.tar.gz | xargs dirname | sort | uniq
Remount "/system" with read only permission
mount -o remount,ro /system
change the owner and group of all the directories in the current folder and /home/admin/data/ to admin & admin
find . /home/admin/data/ -type d -exec chown admin.admin {} \;
find all the files that are modified in the last 1 day
find -mtime +0 -mtime -1
Rename all files in current directory to lowerase, overwriting any existing files.
rename -f 'y/A-Z/a-z/' *
Save a list of all the files/directories under current directory tree to a file named 'foo'
find . -fprint foo
Find all *.tex files/directories in maximum 2 levels down the current directory
find . -maxdepth 2 -name '*.tex'
change the permissions of all the directories in the current folder
chmod 751 `find ./ -type d -print`
find all the files in the file system which have been changed in the last 24 hours.
find / -ctime -1
find all text files in current folder and trim the extra spaces in all lines in these files
find . -type f -name '*.txt' -exec sed --in-place 's/[[:space:]]\+$//' {} \+
Saves hostname that matches ${ip_address} in 'host' variable, without trailing dot.
host=$(dig +short -x "${ip_address}" | sed 's/\.$//g')
Delete the text matched by the regex '<script>if(window.*<\/script>' in all index.html files under current directory
find index.html | xargs -rt sed -i 's/<script>if(window.*<\/script>//g'
List files named "accepted_hits.bam" in the current directory tree prefixing their names with "somecommand"
find `pwd` -name "accepted_hits.bam" | xargs -i echo somecommand {}
display all regular/normal files in the current folder that were accessed exactly 7*24 hours back
find . -type f -atime 7
Find directories named `doc' in /usr and below
find /usr \( -name doc -and -type d \)
Print pathname of a file that is connected to the standard output of the command "yes"
echo <
Remove all files with the .c extension in the current directory tree
find . -name "*.c" | xargs rm -rf
Remove all files under /home/user/Maildir/.SPAM/cur
find /home/user/Maildir/.SPAM/cur -type f | xargs rm
Display all the files/directories under '/home/bozo/projects' directory tree that have been modified within the last day
find /home/bozo/projects -mtime -1
Delete all regular files with '.txt' extension that were modified in more than 25 minutes ago in maximum 1 level down the directory '/home/u20806/public_html'
find /home/u20806/public_html -maxdepth 1 -mmin +25 -type f -name "*.txt" -delete
Find all files/directories not with the name 'query_to_avoid' under current directory
find \! -name "query_to_avoid"
Unset the executable bit of all regular files from directory trees arch, etc, lib, module, usr, xpic
find arch etc lib module usr xpic -type f | xargs chmod -x
Immediately kill all child processes of parent process whose ID is specified by the variable PPID.
ps -o pid= --ppid $PPID | xargs kill -9
Archive showing progress all files in "/media/2TB\ Data/data/music/" to "/media/wd/network_sync/music/" excluding files matching "*.VOB", "*.avi", "*.mkv", "*.ts", "*.mpg", "*.iso", "*ar", "*.vob", "*.BUP", "*.cdi", "*.ISO", "*.shn", "*.MPG", "*.AVI", "*.DAT", "*.img", "*.nrg", "*.cdr", "*.bin", "*.MOV", "*.goutputs*", "*.flv", "*.mov", "*.m2ts", "*.cdg", "*.IFO", "*.asf", and "*.ite"
rsync -av --progress --exclude=*.VOB --exclude=*.avi --exclude=*.mkv --exclude=*.ts --exclude=*.mpg --exclude=*.iso --exclude=*ar --exclude=*.vob --exclude=*.BUP --exclude=*.cdi --exclude=*.ISO --exclude=*.shn --exclude=*.MPG --exclude=*.AVI --exclude=*.DAT --exclude=*.img --exclude=*.nrg --exclude=*.cdr --exclude=*.bin --exclude=*.MOV --exclude=*.goutputs* --exclude=*.flv --exclude=*.mov --exclude=*.m2ts --exclude=*.cdg --exclude=*.IFO --exclude=*.asf --exclude=*.ite /media/2TB\ Data/data/music/* /media/wd/network_sync/music/
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 {} \;
Add cron lists from "filename" to list of cron jobs, giving errors for any lines that cannot be parsed by crontab.
crontab filename
Copy all files in "/path/to/local/storage" to "/path/to/copy" on host "remote.host" authenticating as user "user"
rsync /path/to/local/storage [email protected]:/path/to/copy
Report file system '/dev/disk0s2' disk usage
df | grep /dev/disk0s2
Find all files under current directory and search for 'something' in those files
find . -print | xargs grep something
Find all files/directories with '.err' extension under '/home/username' directory tree
find /home/username/ -name "*.err"
Search all files in the current directory tree whose names end in "1" for string "1"
find . -name "*1" -print0 |xargs -0 grep "1"
Copy an entire file structure, creating empty files in the copy instead of copying the actual files.
find src/ -type d -exec mkdir -p dest/{} \; -o -type f -exec touch dest/{} \;
list all files under $dir directory except path $dir/prune_me directory
find "$dir" -not -path "$dir/prune_me*" -exec bash -c 'echo "$0"' {} \;
Replace all instances of "string" with "longer_string" in file "input.txt" and re-align
cat input.txt | sed 's/string/longer_string/g' | column -t
Search for files/directories which are writable by either their owner or their group
find . -perm /u+w,g+w
find all the xml files in the current folder which are present in the pattern text file
find . -name "*.xml" -exec grep -HFf < {} \;
Print the number of lines for each *.txt file from the $DIR directory tree
find $DIR -name "*.txt" -exec wc -l {} \;
Report file system mounted at $path_in_question disk usage if canonical path $path_in_question is a mount point.
df $path_in_question | grep " $path_in_question$"
Remove all files under /home/user/Maildir/.SPAM/cur
find /home/user/Maildir/.SPAM/cur -type f -exec rm -f '{}' '+'
Print the path names of all files and directories in the current directory tree
find -printf '"%h/%f" '
Save the absolute path of the current script to variable "SELF"
SELF=`readlink /proc/$$/fd/255`
Print the list of all regular files in the current directory and below
find . -type f
Find files/directories named blah under current directory
find ./ -name blah
change the permissions of all the directories in the folder "/path/to/someDirectory" to 755
sudo find /path/to/someDirectory -type d -print0 | xargs -0 sudo chmod 755
Change permission to 755 of all files/directories under current directory tree that have 777 permission
find -perm 777 | xargs -I@ sudo chmod 755 '@'
Change the ownership of all files in the current directory tree from root to www-data
find -user root -exec chown www-data {} \;
search for all mp3 files in the folder /home/you which have been accessed exactly 10*24 hours ago
find /home/you -iname "*.mp3" -atime 10 -type -f
Delete all empty files and directories in the "test" directory tree
find test -depth -empty -delete
Search for command "tail" in the maps of the process with PID 2671
cat /proc/2671/maps | grep `which tail`
Append the current date in '%d%m%Y-%H-%M' format, '_' and the current username, then save it in 'name' variable
name="$_$"
Find all *.axvw files/directories under current directory
find . -name '*.axvw'
Create a symbolic link relative to link location named "$dest_dir/$orig_name" to "$orig_dest"
ln -r -s "$orig_dest" "$dest_dir/$orig_name"
List the files from the current directory tree that contain lines matching regular expression '^From:.*unique sender', ignoring ~/src and ~/bin
find . -name bin -prune -o -name src -prune -o -type f -print | xargs egrep -il '^From:.*unique sender'
Search /usr/bin for regular files that were last accessed more than 100 days ago
find /usr/bin -type f -atime +100
Recursively copy all ".txt" files to "[email protected]:/tmp/newdir/"
rsync -rvv *.txt [email protected]:/tmp/newdir/
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 \+
Recursively change "/usr/local" owner to the current user and group to admin
sudo chown -R $(whoami):admin /usr/local
Reports count of processors in system.
grep "^core id" /proc/cpuinfo | sort -u | wc -l
Find all *.php files and *.js files/directories under /home/jul/here excluding *.js files/directories under /home/jul/here/exclude/* paths
find /home/jul/here -type f -iname "*.php" -o -iname "*.js" ! -path "/home/jul/here/exclude/*"
Show the list of files that are not owned by user wnj or are not newer than file `ttt'
find / \! \ -print
find all the files which have the write permission to the group and remove the write permission.
find . -perm -20 -exec chmod g-w {} ;
Insert the current host name on line 15 of "test.html"
sed -i "15i `hostname`" test.html
Move all *.data files/directories in $S directory to $S/data/ directory
find "${S}" -name '*.data' -exec mv '{}' "${S}/data/" \;
Rename file file.txt.123456 to file.txt
mv file.txt.123456 $(ls file.txt.123456 | rev | cut -c8- | rev)
Search the current directory tree for all .java files newer than the file build.xml
find . -name '*.java' -newer build.xml -print
Find all files under current directory whose file type description contains "image", display the paths to files and file type descriptions.
find . -name '*' -exec file {} \; | grep -o -P '^.+: \w+ image'
Read a single character from standard input with prompt "Are you sure? "
read -p "Are you sure? " -n 1