nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Print a sorted list of all .jpg files in the current directory and below
find -name '*.jpg' | sort -n
Save Java home in variable "JAVA_HOME"
JAVA_HOME="$( readlink -f "$" | sed "s:bin/.*$::" )"
find all directories that names are 'apt' and display details
find / -type d -name "apt" -ls
List all .svn files/directories under current directory
find . -name .svn -exec echo {} \;
Save standard input to variable 'stdin' until the first character encoded as '\004' is read
read -d "$(echo -e '\004')" stdin
display all the files in the usr folder and those that are in the path local
find /usr/ -path "*local*"
Find all files matching pattern '.#*' in the current directory tree
find -iname '.#*'
Search the files from the current directory tree for "chrome"
find . -exec grep chrome {} \;
Change the ownership of all files in the current directory tree to myuser:a-common-group-name
find . -exec chown myuser:a-common-group-name {} +
Set shell option 'checkwinsize'.
shopt -s checkwinsize
Search for the string 'magic' in all regular files under current directory tree and display long listing of them
find . -type f -exec grep "magic" {} \; -ls
Find all directories under current directory and set read-write-execute permission for owner, read-execute permission for group and no permission for other for those directories
find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
Set permission of all files in "img", "js", and "html" to 644
chmod 644 img/* js/* html/*
Archive "src" to "dst" without overwriting existing files in "dst"
rsync -a -v --ignore-existing src dst
find all the text files that have modified in the last 2 days and not modified today
find . -name "*.txt" -type f -daystart -mtime +0 -mtime -2
display all the jpg files in the current folder which belong to the user nobody
find . -name *.jpg -user nobody
Delete all .pyc files in the current directory tree
find . -name "*.pyc" | xargs rm -rf
Find all *.mp3 files under current directory and run mplayer with these files
find . -name \*.mp3 -print0 | xargs -0 mplayer
Create an empty file in each directory named "mydir" under current directory.
find . -type d -name "mydir" -print | sed 's/$/\/abc.txt/g' | xargs touch
List all *.c, *.h and *.cpp files under current directory
find . -type f \( -name '*.c' -or -name '*.h' -or -name '*.cpp' \) -exec ls {} \;
Verbosely change ownership of "$file" to "root"
chown -v root "$file"
List in detail regular files from the current directory tree whose names match Perl regular expression '\w+-\d+x\d+\.\w+$'
find -type f | grep -P '\w+-\d+x\d+\.\w+$' | sed -re 's//\\\1/g' | xargs ls -l
display all files in current folder
find .
Print characters 2 through 4 of "abcdefg"
echo 'abcdefg'|tail -c +2|head -c 3
Find all files you have modified in the last two days
find ~ -type f -mtime -2
Print a hex dump of "$DIREC" as characters
echo "$DIREC" | od -c
Creates temporary folder and save path to that in a TMPDIR variable.
TMPDIR=$(mktemp -d)
search for the directory "mysql" in the /etc folder
find /etc -name mysql -type d
Print a single line of numbers from "001" to "010"
yes | head -n 10 | awk '{printf}'
Find all files in the current directory tree with size bigger than 5 MB and sort them by size
find ./ -size +5M -type f | xargs -r ls -Ssh
Print current shell using process ID
ps -p $$
Recursively finds and compresses all files in the directory '/path/to/dir'
find /path/to/dir -type f -exec bzip2 {} \;
find all the text files in the file system and search only in the disk partition of the root.
find / -xdev -name "*.txt"
Replace spaces with underscores in the names of all files and directories in the "/tmp" directory tree
find /tmp/ -depth -name "* *" -execdir rename " " "_" "{}" ";"
find all the files in the current folder that have been accessed in today from the start of the day
find -daystart -atime 0
Search for regular files of the user bluher in the file system
find / -type f -user bluher -exec ls -ls {} \;
Find all file paths under current directory, perform a reverse sort and show first 10 file paths with their status change time
find . -type f -printf "%C@ %p\n" | sort -r | head -n 10
List all mounted filesystems
mount
Filters only directories including hidden ones from long file listing of a current directory, and prints their names.
ls -Al | grep "^d" | awk -F" " '{print $9}'
Prints directory where the executing script is located.
$
Search the "katalogi" directory tree for files named "wzorzec"
find katalogi -name wzorzec
search for all png files in a folder and copy them to another folder
find /home/mine -iname "*.png" -exec sh -c 'cp $0 /home/mine/pngcoppies/copy/$0' {} \;
Check the bit width of static library "libsomefile.a"
readelf -a -W libsomefile.a | grep Class: | sort | uniq
Search the current directory and two levels below for file `teste.tex'
find ~/ -maxdepth 3 -name teste.tex
Create links for all files in the current directory tree that are more than 1000 days old in "/home/user/archives"
find . -type f -mtime +1000 -print0 | cpio -dumpl0 /home/user/archives
Find all files under $root_dir
find $root_dir -type f
find case-insensitive StringBuffer in all *.java files
find . -type f -name "*.java" -exec grep -il string {} \;
Find all php files in current directory and delete lines matching the regex '<\?php \/\*\*\/eval(base64_decode);.*\?>' in those files
find . \ -exec grep -Hn "<\?php /\*\*/eval(base64_decode);.*\?>" {} \; -exec sed -i '/<\?php \/\*\*\/eval(base64_decode);.*\?>/d' {} \;
print disk usage of files or folders in current directory
du -sh *
Save the latest modification time (in format "%T@ %t" of any file under "./$dir" to variable "timestamp"
timestamp=$
search for a file using name patterns from the list of all the regular files in the folder project and save the output to the file Include.
find project -type f -print | egrep '$' > Include
Search the ~/Books directory recursively for regular files named "Waldo"
find ~/Books -type f -name Waldo
Find files/directories named 'photo.jpg' in the entire filesystem
find / -name photo.jpg
Find all files that contain the case insensitive regex 'stringtofind' in maximum 1 level down the / directory without descending into other partitions
find / -maxdepth 1 -xdev -type f -exec grep -Zli "stringtofind" {} +
Remove all regular files from the current directory tree that were modified a day ago
find . -type f -mtime 1 -exec rm {} +
Prints long listing of content in the current folder with C-style escapes for nongraphic characters
ls -lb
Make directory "/var/svn"
sudo mkdir /var/svn
change the permissions of all the regular files in the folder root_dir to 444
find root_dir -type f -exec chmod 444 {} \;
Gets IP address of only primary network interface.
ifconfig $ | grep 'inet ' | awk '{print $2}' | grep -Eo '{3}[0-9]*'
Send SIGKILL signal to processes ID 18581, 18582, and 18583, killing them instantly.
kill -9 18581 18582 18583
Display permissions, user, group, and full path for each file in the current directory tree
tree -p -u -g -f
Search the *.code files from the current directory tree for string 'pattern'
find . -name '*.code' -exec grep -H 'pattern' {} +
display all the regular/ normal files in a folder
find src/js -type f
Calculate md5 sum of files $source_file and $dest_file
md5sum "$source_file" "$dest_file"
Remove all files in the current directory tree that have the name "abc.xxx"
find . -name abc.xxx -exec rm {} \;
Send SIGHUP (hangup) signal to all parents of zombie processes.
kill -HUP $(ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }')
Merge already sorted files "*.txt" and split the result into files of at most 1000000 lines each with a numeric suffix and a prefix "output"
sort -m *.txt | split -d -l 1000000 - output
sort each file in the bills directory, leaving the output in that file name with .sorted appended
find bills -type f | xargs -I XX sort -o XX.sorted XX
Create a symolic link in "/usr/local/bin/" to "/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/
find all the files in the current folder which have execute permission to all the users
find . -perm /u=x,g=x,o=x
Search for the regex 'pattern_to_search' in all files under '/directory/containing/files' and show the matched lines as well as the file names
find /directory/containing/files -type f -exec grep -H 'pattern_to_search' {} +
Find all directories in the current directory tree
find -type d
Replace all occurrences of '2013 Magento Inc.' with '2012 Magento Inc.' in all files with '.php, '.xml' and '.phtml' extensions under current directory tree
find . -name '*.php' -print0 -o -name '*.xml' -print0 -o -name '*.phtml' -print0 | xargs -0 sed -i '' 's/2013 Magento Inc./2012 Magento Inc./g'
Print amount of space available on the file system containg path to the current working directory.
df . | awk '$3 ~ /[0-9]+/ { print $4 }'
Compress files excluding *.Z files
find . \! -name "*.Z" -exec compress -f {} \;
Search for files/directories which are writable by either their owner or their group
find . -perm /220
Print every 20 bytes of standard input as tab separated groups of bytes 1-3, 4-10, and 11-20
fold -b -w 20 | cut --output-delimiter $'\t' -b 1-3,4-10,11-20
List files ending in .html and residing in the current directory tree
find . -name "*.html"
Find all the files under /tmp directory and show a few lines of output from the beginning
find /tmp | head
Output lines 16224 to 16482 of 'file', not recommended with large files that contain many lines after the ones needed.
awk 'NR==16224, NR==16482' file
change cgi files to mode 755 under htdocs or cgi-bin directories
find htdocs cgi-bin -name "*.cgi" -type f -exec chmod 755 {} \;
Gets the groups these users belong to.
groups a b c d
Move each of the directories in /path/to/folders/* to another directory whose name is constituted by appending .mbox to each directory name and create a directory named Messages in this directory
find /path/to/folders/* -type d -exec mv {} {}.mbox \; -exec mkdir {}.mbox/Messages \;
find all files under the current folder except dir1 dir2 dir3 folder
find . -type d \ -prune -o -print
Copy "/home/username/path/on/server/" to "[email protected]:/Users/username/path/on/machine/" and convert encoding from UTF-8 to UTF-8-MAC
rsync --iconv=UTF-8,UTF-8-MAC /home/username/path/on/server/ '[email protected]:/Users/username/path/on/machine/'
change the permissions of all regular/normal files in the current directory
find . -type f | xargs chmod 664
Search for "pattern" in all the .c files in the current directory tree
find . -name "*.c" | xargs grep pattern
display all the files in current folder
find .
Replace all occurrence of "subdomainA.example.com" with "subdomainB.example.com" in all files under /home/www and below
find /home/www/ -type f -exec sed -i 's/subdomainA\.example.com/subdomainB.example.com/g' {} +
Find all files/directories which have been modified within the last day in the drectories/files taken from the glob pattern '/tmp/test/*'
find /tmp/test/* -mtime -1
Get domain name of $ip and save it to the variable 'reverse'
reverse=$(dig -x $ip +short)
Search the current directory for files whose names start with "messages." ignoring SVN, GIT, and .anythingElseIwannaIgnore files
find . -type f -print0 | xargs -0 egrep messages. | grep -Ev '.svn|.git|.anythingElseIwannaIgnore'
Count the number of lines in all ".php" files in the current directory tree
find . -name '*.php' -type f | xargs cat | wc -l
Print first field from semicolon-seprated line <line>.
echo "<line>" | cut -d ";" -f 1
Sort the lines of the file 'temp.txt' and change it in-place
sort temp.txt -otemp.txt
Recursively copy all files with names ending with .txt from dir_1 to the same location within copy_of_dir_1
rsync --recursive --prune-empty-dirs --include="*.txt" --filter="-! */" dir_1 copy_of_dir_1
List all leaf directories under current directory
find -depth -type d | while read dir; do [[ ! $prev =~ $dir ]] && echo "${dir}" ; prev="$dir"; done
Print a colon-separated list of all directories from the ~/code directory tree
find ~/code -type d | tr '\n' ':' | sed 's/:$//'
List all cron jobs for current user.
crontab -l
Print summary of files present only in dir1.
diff -rq dir1 dir2 | grep 'Only in dir1/'