nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Archive "user@host1:/directory/" to "user@host2:/directory2/" via ssh and compressing data during transmission
rsync -azvu -e ssh user@host1:/directory/ user@host2:/directory2/
Removes all empty folders under path '/thepath', printing info message on each operation.
find /thepath -type d -empty -print0 | xargs -0 rmdir -v
Rename "file001abc.txt" to "abc1.txt"
mv file001abc.txt abc1.txt
Find all directories matching the regex '.texturedata' in their names under '/path/to/look/in/' directory tree
find /path/to/look/in/ -type d | grep .texturedata
Recursively remove all "*.txt" files and answer "y" to any prompt
yes | rm -r *.txt
Enables shell option 'nocaseglob'.
shopt -s nocaseglob
Open a ssh connection to "user@host" with a control socket "/tmp/%r@%h:%p"
ssh user@host -S /tmp/%r@%h:%p
find all directories in the current folder and do not search in sub directories
find . -type d -maxdepth 1
Search the home directory tree for video files
find ~ -type f -regex '.*\.\'
returns a list of files modification newer than poop
find . -mnewer poop
find all the ".JPG" files in current folder and display their count
find ./ -name '*.JPG' -type f | wc -l
extract "backup.tar.gz" with verbose output
tar -xzvf backup.tar.gz
Remove all .txt files from the /full/path/dir directory tree
find /full/path/dir -name '*.txt' -print0 | xargs -0 rm
Print /some/dir/ if it's empty
find /some/dir/ -maxdepth 0 -empty
Sets shell option 'nullglob'.
shopt -s nullglob
find all the perl files in /var/www ( case insensitive search )
find /var/www/ -type f -iname "*.pl" -print
search for the pattern "tgt/etc/file1" in the files tgt/etc/file2, tgt/etc/file3
find . -type f -name \* | grep tgt/etc/file1 tgt/etc/file2 tgt/etc/file3
Find all files named "file.ext" within the current folder and print the path where each one is located
find `pwd` -name "file.ext" -exec echo $ \;
Make "file.sh" executable
chmod +x file.sh
Find all the files whose name is tecmint.txt in the current directory
find . -name tecmint.txt
Exclude directory from find . command
find -iname example.com | grep -v beta
display all files in a folder
find "/proc/$pid/fd"
Find movies over a gigabyte in size
find ~/Movies/ -size +1024M
Split "file.txt" into files of at most 1 MiB in size with a numeric suffix, prefix "file", and additional suffix ".txt"
split -b 1M -d file.txt file --additional-suffix=.txt
find all the hidden files in the temp folder
find /tmp -type f -name ".*"
Find all files/directories named 'openssl' under current directory tree without printing 'Permission denied' error messages
find . -name "openssl" | sed '/Permission denied/d;'
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name vmware-*.log | xargs -i rm -rf {}
Print the directory of the full path to the current script
echo $(dirname $(readlink -m $BASH_SOURCE))
Find all pdf files in current directory and grep with the regex expanded by "$1" in the converted text output and print the paths to the matching files
find . -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "$1"' -- "$1" \;
Remove trailing white spaces from all files under current directory ignoring .git and .svn directories
find . -not \( -name .svn -prune -o -name .git -prune \) -type f -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//"
Find all files on the system whose names are 'composer.json'
find / -name composer.json
Find all regular files under ${path} without following symlinks
find ${path} -P -type f
display a long listing of all the "Trash" files in the folder /home
find /home -name Trash -exec ls -al {} \;
Remove all *.mp3 files in tmp directory but not in it's subdirectories
find tmp -maxdepth 1 -name *.mp3 -print0 | xargs -0 rm
Stores system load average number in the 'proc_load_average' variable.
proc_load_average=$
Parse output from "script.sh" in the current directory which is expected to generate "variable: value" formatted data, and add the resulting variables to the current shell's environment.
source <(./script.sh | sed -rn '/volume/{s#/dev/[[:space:]]+#\1=#;p}')
Recursively change ownership of "/usr/local" to the current user
sudo chown -R `whoami` /usr/local
Read the first 10 characters from standard input in an interactive shell into variable "VAR"
read -n10 -e VAR
List files in directory "one" and "two" that do not exist in the other
sort < < | uniq -u
Recursively finds string with text "foo" in all files of a current folder.
find ./ -type f | xargs grep "foo"
Find files with 777 permissions and change them to 755
find / -type f -perm 0777 -print -exec chmod 755 {} \;
Find all symlinks in the /myfiles directory tree
find /myfiles -type l
List all .jpg files in the home directory tree
find . -name "*.jpg" -print0 | xargs -0 ls
delete all the log files in the current folder
find -name '*.log' -delete
Find the passwd file under the root directory and two levels down
find / -maxdepth 3 -name passwd
find all the files in the current folder which end with .o or with the name a.out and display them.
find . -print
Print contents of "file" as space separated hexadecimal bytes on a single line
xxd -p file | tr -d '\n'
list the regular files in your home directory that were modified yesterday
find ~/ -daystart -type f -mtime 1
Print the full path of command "gcc"
which gcc
Non-recursively finds all '*.pdf' files in a current folder and removes them.
find -maxdepth 1 -name '*.pdf' -exec rm "{}" \;
Find all the .mp3 files in the music folder recursively and pass them to the ls command
find ./music -name "*.mp3" -print0 | xargs -0 ls
Finds all files having text "texthere" recursively in a current folder, and precedes found string with string number in file and file name.
find -type f -exec grep -Hn "texthere" {} +
Find all directories under foldername directory and set their permission to 755
sudo find foldername -type d -exec chmod 755 {} ";"
delete all the regular files in the temp folder which have not been modified in the last 24 hours + at the end gives bulk input to the rm command
find /tmp/ -type f -mtime +1 -exec rm {} +
Find all $2 files in $1 path and search for the regex expanded by $3 in those files
find $1 -name "$2" -exec grep -Hn "$3" {} \;
create symbolic links in directory "/your/dest/dir/" to all files located in "/your/source/dir/" and have filename extension "txt.mrg"
find /your/source/dir/ -iname '*.txt.mrg' -exec ln -s '{}' /your/dest/dir/ \;
find the regular js files which path does not contains '*/test/*' and name does not contains '*-min-*' or '*console*'
find . ! -path "*/test/*" -type f -name "*.js" ! -name "*-min-*" ! -name "*console*"
Archive "/path/to/copy" to "/path/to/local/storage" on host "host.remoted.from" as user "user" updating files with different checksums, showing human readable progress and statistics, and compressing data during transmission
rsync -chavzP --stats /path/to/copy [email protected]:/path/to/local/storage
Change the owner of all files in the directory tree "dir_to_start" excluding directory "dir_to_exclude" to "owner"
find dir_to_start -name dir_to_exclude -prune -o -print0 | xargs -0 chown owner
find all files and directories under the current directory and display the blocksize and the quoted filename, using the stat command
find . -type f -exec stat -c "%s %N" {} \;
Remove empty directories
find -type d -exec rmdir --ignore-fail-on-non-empty {} + ;
Print unique lines in "file_a" and "file_b"
sort file_a file_b|uniq -u
Prints random line from file $FILE.
sort --random-sort $FILE | head -n 1
Search for case insensitive pattern 'search for me' in all files that match the name pattern '*.[!r]*' under current directory tree
find . -name "*.[!r]*" -exec grep -i -l "search for me" {} \;
Print DISPLAY of "orschiro" user
who | awk -F '[()]' '/orschiro/{print $(NF-1)}' | grep -v orschiro | uniq
Find all files in the current directory tree that were last changed $minutes minutes ago
find . -cmin $minutes -print
Find all files with the name "MyProgram.c" in the current directory and all of it's sub-directories.
find -name "MyCProgram.c"
Find all files under current directory that were modified less than 1 day ago
find -mtime -1
Create a full path symbolic link "$newlink" from a relative path symbolic link "$origlink"
ln -s $(readlink -f $origlink) $newlink
Report all C language source code files under the current directory
find . -name \*.c -print
Print numbers from 1 to the number in variable "$1"
seq $1
Prints a random number between 2000 and 65000
head -200 /dev/urandom |cksum | cut -f1 -d " " | awk '{print $1%63000+2001}'
Recursively removes all files and folders named '.svn' in a current folder.
find . -name .svn -exec rm -rf {} +
Unsets all environment variables with 'G4' in name.
unset $
find all the files in the directory which is pointed by $1 variable ending with the name held in the variable $2 or having the extension of value saved in the argument $2.
find $1 \( -name "*$2" -o -name ".*$2" \) -print
display all the html files in the current folder that have been modified in the last 7*24 hours
find . -mtime -7 -name "*.html" -print
display the contents of all the files in the current folder which start with test
find . -iname '*test*' -exec cat {} \;
Copy "6.3.3/6.3.3/macosx/bin/mybinary" to "~/work/binaries/macosx/6.3.3/" and create directory "~/work/binaries/macosx/6.3.3/" if "~/work/binaries/macosx/" exists
rsync 6.3.3/6.3.3/macosx/bin/mybinary ~/work/binaries/macosx/6.3.3/
Display all environment variables, functions, and aliases, pausing for user interaction after each page of output.
set | more
Create a symbolic link named "${DESTINATION}${file}" to "${TARGET}${file}"
ln -s "${TARGET}${file}" "${DESTINATION}${file}"
Remove all directories called "test" from the current directory tree
find . -name test -type d -print0|xargs -0 rm -r --
list all files under the current directory, writing the output to the file some_file, suppressing all error messages
find . 2>/dev/null > some_file
Prints logged in users in sorted order.
w | sort
Find all files starting from the current directory which are smaller than 100MB
find . -size -100M
Find all files/directories that are not newer than Jul 01 by modification time
find /file/path ! -newermt "Jul 01"
Show the current UTC date in '%Y-%m-%dT%k:%M:%S%z' format
date -u '+%Y-%m-%dT%k:%M:%S%z'
Make directory "~/practice"
mkdir ~/practice
Remove all files from the system whose path names contain "GUI"
find / -type f -print0 | xargs -0 grep -liwZ GUI | xargs -0 rm -f
Print 'This should print the filename twice if an implicit -print is applied: ' appended with file paths for all files named 'file' under current directory tree
find -name file -exec echo 'This should print the filename twice if an implicit -print is applied: ' {} +
Copy all regular files whose names end in "~" from the /path directory tree to ~/backups/
find /path -type f -name '*~' -print0 | xargs -0 -I % cp -a % ~/backups
find all the text files in the current folder and do not search in somedir, bin directories
find . \ , \ -o \
Gets list of IP addresses of all network interfaces.
ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'
List all files in current directory whose name or file type description contains the word "ASCII".
file * | grep ASCII
Write output of "command" to standard output and append to "/path/to/logfile"
command | tee -a /path/to/logfile
Find all files/directories under '/directory_path' directory tree that have been modified within the last day
find /directory_path -mtime -1 -print
Find directory "your/dir" if it is empty
find your/dir -prune -empty
Unsets random one from first four array members.
unset array[$RANDOM%4]
search for a pattern in all the python files in the current folder. and save the output to output.txt file
find . -name '*.py' -exec grep 'something' {} \; > output.txt
Print current shell settings
set -o
Removes all files from current folder but 5 newest ones.
ls -tr | head -n -5 | xargs rm