nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
extract "backup.tar.gz" with verbose output
tar -xzvf backup.tar.gz
Convert all markdown files on the system to html
find / -name "*.md" -type f -exec sh -c 'markdown "${0}" > "${0%.md}.html"' {} \;
Delete all empty directories in the "test" directory tree
find test -depth -type d -empty -delete
Find all TXT files that belong to user root
find / -user root -iname "*.txt"
Compresses all files listed in array $*, executing in background.
compress $* &
Prints process tree with command line arguments and process id numbers.
pstree -apl
Write "ee" to standard output of the current terminal and as input to command "foo"
t=$ echo ee | tee $t | foo
find all .pm, .pl files in /users/tom and search for multiple pattern in same files and display the matched file names
find /users/tom -name '*.p[lm]' -exec grep -l -- '->get(' {} + | xargs grep -l '#hyphenate'
Find all directories under /path/to/dir (no sub-directories) and archive them (with relative paths) into files with .tar.gz extension
find /path/to/dir -mindepth 1 -maxdepth 1 -type d -execdir sudo tar -zcpvf {}.tar.gz {} \;
Calculate md5 sum of file ${my_iso_file} and save it to variable 'md5'
md5="$(md5sum "${my_iso_file}")"
Removes resursively all files and folders named ".DS_Store".
find . -name ".DS_Store" -print0 | xargs -0 rm -rf
Find all directories under ~/code without descending into hidden directories and print them appended with :
find ~/code -name '.*' -prune -o -type d -printf ':%p'
Identify files that do not have a listing in the /etc/passwd or /etc/group file
find / -nouser -o -nogroup
Search for "pattern" in "file" and separate each line with '" "'
cat file | grep pattern | paste -sd'~' | sed -e 's/~/" "/g'
Search the current directory tree for regular files last changed more than 14 days ago
find -type f -ctime +14
Move "phantomjs-1.8.1-linux-x86_64.tar.bz2" to "/usr/local/share/" directory
sudo mv phantomjs-1.8.1-linux-x86_64.tar.bz2 /usr/local/share/.
List the MD5 digest of all files under "teste1" and "teste2" sorted alphabetically
find teste1 teste2 -type f -exec md5 -r {} \; | sort
display all the files in the current folder along with the modification time and display file names of the last 10 modified files
find . -type f -printf '%T@ %p\n' | sort -n | tail -10 | cut -f2- -d" "
Get the PID of rsync for the user that owns the process matching the pattern expanded by CID$client_id
pstree $ -ap | sed -n 's/.*rsync,\.*/\1/p'
Replace all matches with the regex expanded by $P_FROM with the text expanded by $P_TO in all regular files under current directory not going into subdirectories and modify the files in-place
find . -type f -maxdepth 1 -exec sed -i "s/$P_FROM/$P_TO/g" {} \;
Delete all files under $INTRANETDESTINATION/weekly directory tree that were modified more than 32 days ago
find $INTRANETDESTINATION/weekly -mtime +32 -exec rm {} \;
print lines from last match of ^Statistics until end of file
tac INPUTFILE | sed '/^Statistics |/q' | tac
Answer "y" to any prompts in the interactive recursive removal of "dir1", "dir2", and "dir3"
yes y | rm -ir dir1 dir2 dir3
Display human-readable file type description of utf8.txt
file utf8.txt
Find files named "ppp.conf" in the /etc directory tree
find /etc -name ppp.conf
Find all *.rb (regular) files under current directory and print them on stdout putting the file name/path in-between two string literals 'Hello,' and '!'
find . -name "*.rb" -type f | xargs -I {} echo Hello, {} !
Finds users with X session in system and puts the result in USERS variable.
USERS=$(w | awk '/\/X/ {print $1}')
display all the files in the home folder which are smaller than 500 bytes
find ~ -size -500b
Show directory sizes in KB and sort to give the largest at the end
find . -type d -exec du -sk {} \; | sort -n -k 1
SSH into SERVER, execute "command," and start up a login shell when it completes
ssh -t SERVER 'command; bash -l'
Send SIGTERM (signal 15) signal to all process whose username is "username" and whose command is "your_command".
ps -o uid,pid,cmd|awk '{if($1=="username" && $3=="your_command") print $2}'|xargs kill -15
Change directory to the download directory specified in the current user's user-dirs.dirs file
cd "$(grep DOWNLOAD $HOME/.config/user-dirs.dirs | cut -f 2 -d "=" | tr "\"" "\n" | tr -d "\n")"
Prints list of all libraries linked with binaries in '/bin/' and '/usr/bin/', with number of linkages for each library.
ldd /bin/* /usr/bin/* | sed -e '/^[^\t]/ d; s/^\t\\?\ (.*/\2/g' | sort | uniq -c
keep only read access to all the files in a directory.
find /path/to/dir ! -perm 0644 -exec chmod 0644 {} \;
display all the files in current directory with each file name displayed twice in the same row
find . | sed 's/.*/& &/'
Gets string with IP4 address of en0 network interface.
ifconfig en0 | grep inet | grep -v inet6
Find all files/directories under mnt/naspath without descending into .snapshot directory, calculate the total size and redirect the result to /tmp/size.log file
find /mnt/naspath -mtime 0 -name .snapshot -prune -o \ | du --files0-from=- -hc | tail -n1 >> /tmp/size.log
Find all directories under current directory and change their permission to 755
find . -type d -exec chmod 755 {} \;
Remove all *.bak files under current directory
find . -type f -name \*.bak -print0 | xargs -0 rm -v
Find all files whose names end with "~" in the /home/peter directory tree, following symlinks, and delete them
find -L /home/peter -name *~ -exec rm '{}' +
Delete all .pyc files in the current directory tree
find . -name "*.pyc" | xargs -0 rm -rf
Find all `doc.txt' files in the current directory tree printing "found" for each of them
find ./ -name doc.txt -printf "found\n"
Prints process tree of the current command process.
pstree -p $$
Report total file systems disk usage in 1T blocks.
df --total -BT | tail -n 1
Find all files under current directory, calculate their md5sum and print the output to MD5SUMS
find . -type f -exec md5sum {} \; > MD5SUMS
Find all files which belong to user lal and change their ownership to ravi
find / -user lal -exec chown ravi {} \;
change the permission of all the normal/regular files from 777 to 755 in the folder "/home/user/demo"
find /home/user/demo -type f -perm 777 -print -exec chmod 755 {} \;
Find all files/directories under /home/baumerf/public_html/ that were modified less than 60 minutes ago excluding *.log files/directories
find /home/baumerf/public_html/ -mmin -60 -not -name \*.log
Find directories that are directly under /home/user/workspace directory (no-subdirectories) and were modified more than 30 days ago and print a message saying that the directory wasn't modified during last 30 days
find /home/user/workspace -mindepth 1 -maxdepth 1 -type d -mtime +30 -printf "\t- It seems that %p wasn't modified during last 30 day\n"
Copy the current directory tree to '/path/to/destination/dir' preserving permissions, timestamp and ownership
find . | cpio -pdumv /path/to/destination/dir
Find all files, folders, symlinks, etc in the current directory recursively
find .
Find all files under /home/feeds/data without descending into *def/incoming* and *456/incoming* paths
find /home/feeds/data -type f -not -path "*def/incoming*" -not -path "*456/incoming*"
Finds strings with 'TEXT' from *.log files and prints all but first field from any space-delimited string.
grep -e TEXT *.log | cut -d' ' --complement -s -f1
Print the date formatted with "%a %x %X" followed by the host name
echo `date +"%a %x %X"` `hostname`
Removes all empty folders that ends with any-cased '*.bak' under '/Users/' path.
find /Users -type d -iname '*.bak' -print0 | xargs -0 rmdir
Recursively change the group of all files in "/tmp/php_session" to "daemon"
chown -R :daemon /tmp/php_session
Print the contents of all file* files under current directory
perl -ple '' `find . -name "file*"`
Print history with the first field removed
history | awk '{sub($1, "", $0); sub(/^[ \t]+/, "", $0); print}'
Copy "/Users/username/path/on/machine/" to "[email protected]:/home/username/path/on/server/" and convert encoding from UTF-8-MAC to UTF-8
rsync --iconv=UTF-8-MAC,UTF-8 /Users/username/path/on/machine/ '[email protected]:/home/username/path/on/server/'
Prints path to the folder that contains target of symbolic link ../../../../etc/passwd.
$(dirname $)
Find all C source code files from the current directory tree that contain "keyword" in their pathnames, ignoring the case
find . -type f \( -iname “*.c” \) |grep -i “keyword”
Update the history file in the current session
history -w
Copy all files and directories under the current directory into "../new" preserving relative paths
find -print0 | sort -z | cpio -pdv0 ../new
Print your/dir if it's an empty directory
find your/dir -prune -empty -type d
Move "file1", "file2", "..." to "target" directory
mv -t target file1 file2 ...
Create a local SSH tunnel from "localhost" port 16379 to "localhost" port 6379 using key "keyfile.rsa" and disables the interactive shell
ssh -i keyfile.rsa -T -N -L 16379:localhost:6379 someuser@somehost
move all the html files from current folder to another folder and if a symbolic link is found copy the original referenced file and not the link
find . -follow -iname '*.htm' -print0 | xargs -i -0 mv '{}' ~/webhome
Save full path of command "rm" to variable "RM"
RM=`which rm`
start from current directory, skip the directory src/emacs and print it then skip all files and directories under it, and print the names of the other files found
find . -wholename './src/emacs' -prune , -print
Find all files in the current directory tree whose names are "file_name", except for those with pathnames matching pattern "./dirt to be Excluded/*"
find ./ -iname file_name ! -path "./dirt to be Excluded/*"
Find and delete all files with a used disk size of 0
rm `du * | awk '$1 == "0" {print $2}'`
Read and execute file 'lib/B' that located in the same directory as the current script, will fail if currently running script is not in PATH.
source "$( dirname "$" )/lib/B"
Copy the owner and group from "file.txt" to "$tempfile"
chown --reference=file.txt -- "$tempfile"
Find all 400 permission files under /data directory
find /data -type f -perm 400
display all the text files in a folder
find $1 -type f -name '*'$n'.txt'
Find files on the system whose names begin with either x or X
find / -name "[Xx]*"
Search the current directory tree for files named "somename", case insensitive
find -iname 'somename'
Find all .core files on the system starting from / and delete them
find / -name "*.core" -print -exec rm {} \;
Print a sorted list of the extensions of the regular files from the current directory tree
find . -type f -name "*.*" | awk -F. '{print $NF}' | sort -u
Send Output From Find The Find Command To A File
find / -name *.mp3 -fprint nameoffiletoprintto
returns a list of files create time is 1 minute ago under the root directory.
find / -newerct '1 minute ago' -print
Replace spaces with underscores in the names of all files and directories in the current directory tree
find . -depth -name '* *' | while IFS= read -r f ; do mv -i "$f" "$/$" ; done
Print the current date followed by ": $line"
echo "$: " $line
find all the files in the home folder that belong to a specific user
find /home -user <usernmae> -print
display all the ".c" files in the current directory
find . -name \*.c -print
Force create a symbolic link without dereferencing named "$SYMLINK_PATH" to "$lastModified"
ln -nsf $lastModified $SYMLINK_PATH
find all file name in curent directory , -exec will file all file output awk used here for print only file name .
find . -type f -exec ls -lrt {} \; |awk -F' ' '{print $9}'
Set the timestamp of B to the same one as A
touch -r A B
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
Print full path of command "python2.7"
which python2.7
Execute 'python -m unittest discover 2>&1 | pyrg' every second and display with color support
watch -n 1 --color 'python -m unittest discover 2>&1 | pyrg'
Check if current shell is running within a 'screen' process.
pstree --show-parents -p $$ | head -n 1 | sed 's/\(.*\)+.*/\1/' | wc -l
Generate a random 32 ASCII character password from /dev/urandom and save it to variable 'pass'
pass=$
Removes 'subversion' packages from system.
yum remove subversion
Sets shell options 'extglob' and 'nullglob'.
shopt -s nullglob extglob
Find all files/directories in the paths expanded by the glob pattern '.*'
find .*
Print pathnames of all files in the current directory and below skipping directories named SCCS and files in them
find . -name SCCS -prune -o -print
Reverse the order of lines in "myfile.txt" using BSD "tail" command
tail -r myfile.txt
search for al cpp files in current folder and display unique parent directory of these files in sorted order
find . -name "*.cpp" -exec dirname {} \; | sort -u
search for the file foo.txt in the current folder and open it in vi editor
find -name foo.txt -execdir vim '{}' ';'