nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
create directory /tmp/foo
mkdir /tmp/foo
Search the system for the file “testfile.txt” ignoring the case
find / -iname "testfile.txt"
Print a list of all files and directories in the /var/log directory tree
find /var/log/
display all the regular/normal files in a folder
find ./subdirectory/ -type f
Change owner to "$1" and group to "httpd" of ".htaccess"
chown $1:httpd .htaccess
Delete all files in the /myDir directory tree that were last modfied more than 7 days ago
find /myDir -mindepth 1 -mtime +7 -delete
Delete files in the DIR directory tree whose names begin with "2015" and contain "album" or "picture"
find DIR \( -name 2015\* -a \( -name \*album\* -o -name \*picture\* \) \) -delete
Read a line from standard input with prompt "<Your Friendly Message here> : y/n/cancel" and save the response to variable "CONDITION"
read -p "<Your Friendly Message here> : y/n/cancel" CONDITION;
display all files in the current folder which start with met
find -name met*
Ping every address from 192.168.0.1 to 192.168.0.254 with a timeout of 1 second and filter out no responses
echo $(seq 254) | xargs -P255 -I% -d" " ping -W 1 -c 1 192.168.0.% | grep -E "[0-1].*?:"
find for a word in all the regular files in the current directory
find . -type f -exec grep -li '/bin/ksh' {} \;
Move all Emacs backup files from the current directory tree to ~/backups/
find . -name '*~' -print 0 | xargs -0 -I % cp % ~/backups
Find a directory named 'project.images' case insensitively in the entire filesystem and show it in long listing format
find / -type d -iname "project.images" -ls
Delete all directories in the /myDir directory tree
find /myDir -type d -delete
Find all directories in the /data1/realtime directory tree that were modified within the last 60 minutes
find /data1/realtime -mmin -60 -type d
find all the html files in the current folder which have been modified exactly 7 days ago
find . -mtime 7 -name "*.html" -print
Create a named screen session
screen -x main -p oldwindow -X title blah
Change to directory listed in file '$HOME/.lastdir'
cd `cat $HOME/.lastdir`
search for files starting with memo and which belong to the user ann in the folder /work
find /work -name 'memo*' -user ann -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 \;
display all the files in the file system which have been modified in the last 10 minutes
find / -mmin -10
Find all files/directories named 'file' and print them with null character as the delimiter instead of newline
find -name file -print0
Find all files/directories named orm.properties under current directory
find . -name "orm.properties"
Find files that were modified more than 7 days ago and archive them
find . -type f -mtime +7 | xargs tar -cvf `date '+%d%m%Y'_archive.tar`
Saves value '1' in the $PIPESTATUS variable and returns 0.
false | tee /dev/null
Read a line from standard input into variable "a" without backslash escapes
read -r a
Remove trailing whitespaces in .txt files from the current directory tree
find . -type f -name "*.txt" -exec sh -c 'for i;do sed 's/[[:space:]]*$//' "$i">/tmp/.$$ && cat /tmp/.$$ > "$i";done' arg0 {} +
display a long listing of all the files in the current folder that have been accessed in today from the start of the day
find -daystart -atime 0 -ls
display all the C files or Python files in the folder "euler"
find euler/ -iname "*.c*" -exec echo {} \; -or -iname "*.py" -exec echo {} \;
Archive "source" to "destination" via ssh on port "PORT_NUMBER"
rsync -azP -e "ssh -p PORT_NUMBER" source destination
Display the sizes and filepaths of all files/directories sorted in descending order of size
du -a -h --max-depth=1 | sort -hr
Copy the executable "python2.7" in $PATH to "myenv/bin/python"
cp `which python2.7` myenv/bin/python
Find all files matching "abc*" in the current directory and append "\tok"
find . -name 'abc*' | sed 's/$/\tok/' | column -t
Count and show the number of lines for each PHP files in the current directory tree
find . -name '*.php' | xargs wc -l
change the permissions of all the regular/normal files in the folder "/path/to/someDirectory" to 644
sudo find /path/to/someDirectory -type f -print0 | xargs -0 sudo chmod 644
Find all files/directories under /export/home/someone directory in a remote host and upload the files/directories to ftp://somehost/tmp/
ssh someone@somehost 'cd /export/home/someone && find . -name "*" -print| '
find all files that do not have execute permission to all
find . -type d ! -perm -111
display the count of number of files in the current folder
find | wc -l
Find all files under the current directory and copy their permissions to the same file in "../version1"
find . -type f | xargs -I {} chmod --reference {} ../version1/{}
Delete all regular files that have not been modified in the last 60 weeks under $DIR directory tree
find $DIR -type f -mtime +60w -exec rm {} \;
Print the path names of all .png files in the /home/kibab directory tree
find /home/kibab -name '*.png' -exec echo '{}' ';'
Recursively change the owner and group of "subdir2" to "user2"
chown user2:user2 -R subdir2
Find all files residing in /home/dm/Video or below that were changed less than 7 days ago
find /home/dm/Video -mtime -7
Execute all commands in "commands-to-execute-remotely.sh" on server "blah_server"
cat commands-to-execute-remotely.sh | ssh blah_server
Print the home folder of "$USER_NAME"
finger $USER_NAME | grep Directory | expand | cut -d ' ' -f 2
Find all regular files named postgis-2.0.0 under your home directory
find ~/ -type f -name "postgis-2.0.0"
Numerically sort each line in file "bb" and output the result to console from greatest value to least value
sort -nr bb
Create a symbolic link named "foo" to "/var/cache/apt/archives/bash_4.3-14ubuntu1_amd64.deb"
ln -s /var/cache/apt/archives/bash_4.3-14ubuntu1_amd64.deb foo
Find all *-* files under current directory
find . -type f -name '*-*'
display all the directories in the current folder
find . -type d -print
Clear the in-memory history and read from the current history file
history -cr
Count number of occurences of "123" in the string "123 123 123" (ie. 3)
echo "123 123 123" | grep -o 123 | wc -l
Changes group ownership of '/etc/btsync/[prefered conf name].conf' to 'btsync'.
chgrp btsync /etc/btsync/[prefered conf name].conf
display the name and size of all the regular/normal files in the current folder which are bigger than 50MB
find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Print all the file/directory paths under current directory
find | xargs
Find all files on smbfs mounts and print its information and file type
find $(mount -t smbfs | awk '{print $3}') -mount -type f -ls -execdir file {} \;
Find recursively all files that match "pattern" starting from the directory "dir"
find dir -name "pattern" 2>/dev/null
Change all cron jobs running "anm.sh" to be run every 10 minutes instead of 5 minutes.
crontab -l | sed '/anm\.sh/s#\/5#\/10#' | crontab -
Set the bash prompt to "username@hostname"
PS1="`whoami`@`hostname | sed 's/\..*//'`"
Remove filetype suffix (last dot and following characters if any) from filename
echo $filename | rev | cut -f 2- -d '.' | rev
Change owner to "$FUID" and group to "$FGID" of "$FILE2"
chown $FUID:$FGID "$FILE2"
Verbosely compresses all files on fourth and fifth depth level keeping original files in place.
bzip2 -kv */*/*/*/*
Find all regular files under and below dir/ and change their names from UTF8 to the ASCII/TRANSLIT encoding
find dir/ -type f -exec mv {} $ \;
Remove all .tmp files in and below /tmp
find /tmp -name "*.tmp" | xargs rm
Remove all tmp/*.mp3 files
find tmp -maxdepth 1 -name *.mp3 -print0 | xargs -0 rm
Finds $a pattern in a $b string, and returns exit code 0 if found, suppressing any visible output.
echo $b|grep -q $a
Find all files starting from / whose names end with ".rpm" and change their permissions to 755
find / -name *.rpm -exec chmod 755 '{}' \;
Replace newline with "_" in "file" then search for "_foo_" and output with "_" characters deleted
grep -o "_foo_" < | tr -d '_'
search for all the files in current folder which start with "file2015-0" and move them to another folder
find . -name "file2015-0*" -exec mv {} .. \;
Find all *.html files under current directory and for each file replace the first occurrence of STRING and previous lines with the content of common_header file
find . -type f -name '*.html' -exec sed -i -e '1r common_header' -e '1,/STRING/d' {} \;
Search for files/directories with the case insensitive pattern anaconda.* in var/log directory and create an archive (file.tar) of the last file found
find var/log/ -iname anaconda.* -exec tar -cvf file.tar {} \;
check if named screen session exists
screen -list | grep -q "myscreen"
Write the shell's input to standard error as it is read
set -v
Search the current directory tree for *.wav files that have "export" in their pathnames
find -type f -name "*.wav" | grep export
search for a file in the current folder and prepend the first line
find ./ -name somename.txt -exec sed -e '1i My new text here` {} \;
find all the files in the current folder which do not belong to any user
find . -nouser -ls
find all the files ending with ".coffee" in the current folder and search for the words "re" in each line
find . -name \*.coffee -exec grep -m1 -i 're' {} \;
Search the current directory and directories below for .sql files
find . -name \*.sql
Unzip "$ip" as input to "pax -r"
gunzip -c -d $ip | pax -r
Find all or single file called tecmint.txt under the / directory of owner root
find / -user root -name tecmint.txt
delete all text files from current folder
find . -type f ! -iname "*.txt" -delete
Count the number of regular files with case insensitive name pattern $srchfor under 'teste2' directory tree
find teste2 -type f -iname "$srchfor"|wc -l
display all files in the current folder
find . -print
Returns 0 exit status despite of 'somecommand' execution result.
somecommand | true
find all the text files in the file system and search only in the disk partition of the root.
find / -xdev -name "*.txt"
Remove all directories called "test" from the /path/to/dir directory tree
find /path/to/dir -name "test" -type d -delete
display all the files along with their group name in the folder /home which do not belong to the group test
find /home ! -group test -printf "%p:%g\n"
Find and list all files on your current directory and show a few lines of output from the beginning
find | head
Show the explanation of find's debugging options
find -D help
Rename "original.filename" to "new.original.filename"
mv original.filename new.original.filename
Assign the alias rm2g to a find command that removes any .tar file larger than 2 gigabytes.
alias rm2g="find / -type f -name *.tar -size +2G -exec rm -i {} \;"
Search the /Path directory tree for files matching pattern "file_name*" and containing "bar" in their pathnames
find /Path -name "file_name*" | grep "bar"
Synchronize "/path/to/dir_a" with files in "/path/to/dir_b/" if the files are newer
rsync -rtuv /path/to/dir_b/* /path/to/dir_a
Find all files/directories named 'com.apple.syncedpreferences.plist' under ~/Library directory tree
find ~/Library/ -iname "com.apple.syncedpreferences.plist"
Display process information twice, waiting one second between each, filtering out the header line.
top -b -d2 -s1 | sed -e '1,/USERNAME/d' | sed -e '1,/^$/d'
Save the absolute path of the current script to variable "SELF"
script="`readlink -f "${BASH_SOURCE[0]}"`"
Output success.txt omitting lines whose first field appears in fail.txt - lines in fail.txt must appear in the same order as they do in success.txt.
join -v1 success.txt fail.txt
Counts lines of 'file' file.
wc -l file
Check if a drive with UUID "$UUID" is mounted
mount | grep $(readlink -f /dev/disk/by-uuid/$UUID )
Finds recursively all files having extension .c, .h in '/path/' that contain 'pattern', and prints matched strings with string number and file name.
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"