nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all .rb and .yml files in the /some/path directory tree and replace "some_phrase" with "replacement_phrase" in them
find /some/path -name "*rb" -o -name "*yml" | xargs grep -sl "some_phrase" | xargs sed -i -e 's/some_phrase/replacement_phrase/g'
List all files in /var/www and below that have changed in the last 10 minutes
find /var/www -cmin -10 -printf "%c %pn"
Search the /tmp tree for files between 10kb and 20kb
find /tmp -size +10k -size -20k
Find all files that are set user ID to root
find . -user root -perm -4000 -print
Find all hidden (regular) files under /tmp
find /tmp -type f -name ".*"
Write "suspend" to standard output and to file "/sys/bus/usb/devices/usb3/power/level"
echo suspend | sudo tee /sys/bus/usb/devices/usb3/power/level
Find all directories under 'test' directory tree that match the regex '[course*]' in their paths
find test -regex "[course*]" -type d
Gets IP address of 'en0' selected network interface.
ifconfig en0 | awk '/inet addr/ {gsub("addr:", "", $2); print $2}'
Search the home directory tree for video files
find ~ -type f -name '*.mkv' -o -name '*.mp4' -o -name '*.wmv' -o -name '*.flv' -o -name '*.webm' -o -name '*.mov'
change the permission of all php files in current folder
find . -name "*.php" -exec chmod 755 {} \;
delete all normal/regular files in the current folder which are empty
find . -type f -empty -delete
Creates temporary file in a current folder and saves path to it in 'f' variable.
f=`mktemp -p .`
Get the total sizes of all files under current directory
find . -type f -printf '%p %s\n' | awk '{ sum+=$2}; END { print sum}'
List all files/directories under current directory using comma as the delimiter for different fields in the output
find . -ls|awk 'BEGIN{OFS=","}$1=$1'
search for mp3 files in the folder /mp3collection which are smaller than 5MB
find /mp3collection -name '*.mp3' -size -5000k
Execute md5sum command on files found by the find command
find -iname "MyCProgram.c" -exec md5sum {} \;
Convert "1199092913" to dotted decimal IPv4 address
ping -c1 1199092913 | head -n1 | grep -Eow "[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+"
Get the command line args passed to a running process
ps -fp <pid>
Go to first directory specified in PATH which contains the command 'oracle'
cd $
Find all files/directories with '.xml' extension that start with 'log4j' in their names under '/cygdrive/e/MyDocs/Downloads/work/OATS Domain related/' directory tree, search for files that contain the string 'CONSOLE' in their contents, then search for the string 'ASYNC' in the matched files and display the matched lines along with their filenames
find "/cygdrive/e/MyDocs/Downloads/work/OATS Domain related/" -iname "log4j*.xml" | xargs -I % grep -ilr "CONSOLE" "%" | xargs -I % grep -H "ASYNC" %
Find all regular files named 'Chapter1' under current directory tree
find . -name Chapter1 -type f -print
Make directories "es/LC_MESSAGES" as needed and do not error if it exists
mkdir -p es/LC_MESSAGES
Find all files in /tmp whose names begin with the current user's name followed by "."
find /tmp -maxdepth 1 -name "$USER.*"
Find files/directories named 'file.txt' in the path '/usr/lib/important/'
find / -path /usr/lib/important/*/file.txt
Search the "data" directory tree for files matching pattern 'filepattern-*2009*' and save the result as 'filesOfInterest.txt'
find data/ -name filepattern-*2009* -print > filesOfInterest.txt
Recursively copy "dir_b" to "dir_a" and delete any new files in "dir_a"
rsync -u -r --delete dir_b dir_a
Count the number of lines in "/dir/file.txt"
cat /dir/file.txt | wc -l
Search "input.txt" for regex patterns only matching those listed in "ignore.txt", list the unique lines and prefix with the number of occurrences
grep -of ignore.txt input.txt | sort | uniq -c
find all the xml files in the current folder which are present in the pattern text file
find . -name "*.xml" -exec grep -HFf <(find . -name "*.txt" -printf "%f\n") {} \;
display long listing of all files in the current directory whose size is 24 or 25 bytes .
find . -size -26c -size +23c -exec ls -l '{}' \;
Print lines 347340107 through 347340206 in "filename"
tail -n +347340107 filename | head -n 100
Find all files named 'Makefile' in the /usr/ports directory tree and count the number of lines in them beginning with USE_RC_SUBR
find /usr/ports/ -name Makefile -exec grep ^USE_RC_SUBR '{}' '+' | wc -l
Move each of the 'm?' 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 then move all *.emlx files into this directory
find "$path_to_folders" -name 'm?' -type d -exec mv {} {}.mbox \; -exec mkdir {}.mbox/Messages \; -exec sh -c "mv {}.mbox/*.emlx {}.mbox/Messages" \;
display all the files in the folder /home which do not belong to the group test
find /home ! -group test
split a file "list.txt" into pieces per 600 lines
split -l 600 list.txt
display all the files in the entire file system which begin with "apache-tomcat"
find / -name "apache-tomcat*"
Find all PHP files under current directory that contain only one line
find . -type f -name '*.php' -exec wc -l {} \; | egrep "^\s*1\s"
Find directories in the current directory (no sub-directories) and print them appended with a string literal 'Directory: '
find . -maxdepth 1 -type d -print | xargs -I "^" echo Directory: "^"
Subtract each column in File2 from matching column in File1, output the result in a similarly formatted table
awk 'FNR==NR { for a[$1][i]=$i; next } { for $j-=a[$1][j] }1' File2 File1 | rev | column -t | rev
Find all files/directories under '/home/exampleuser/' directory tree whose names end with 'conf' and were modified exactly 3 days ago
find /home/exampleuser/ -name "*conf" -mtime 3
Remove everything in a current folder prompting user on each action.
rm -ri *
Find .rmv files in the ./root directory recursively and copy them to directory /copy/to/here
find root -name '*.rmv' -type f -exec cp {} /copy/to/here \;
Find all *.ogg files under the home directory ignoring the case
find $HOME -iname '*.ogg'
Find all files/directories with '.what_to_find' extension under current directory tree and show the list by excluding paths that contain 'excludeddir1' and 'excludeddir2'
find . -name '*.what_to_find' | grep -v exludeddir1 | grep -v excludeddir2
Get the current shell's executable name from the output of 'ps'.
ps -p $$ | awk '$1 == PP {print $4}' PP=$$
Count the number of unique lines in sorted file "a.txt" compared to sorted file "b.txt"
comm -23 a.txt b.txt | wc -l
Find all files under current directory with 755 permission and change their permission to 644
find . -type f -perm 755 -exec chmod 644 {} \;
Report only total size of file systems in 1T blocks.
df --total -BT | tail -n 1 | sed -E 's/total *([^ ]*).*/\1/'
Display the number of lines in all regular files under current directory tree and also show the total count
find . -type f -exec wc -l {} +
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 dirname {} \;
Print the average round trip time of 5 pings to "google.com" from OSX
ping -c 5 google.com | grep "round-trip" | cut -f 5 -d "/"
Print the base name of the current working directory
echo "$(basename $(pwd))"
find and image in current folder (case insensitive search)
find . -iname "Articles.jpg"
display all the files in the current folder which are in the path ending with the folder f
find . -path '*f'
Calculate the total size of all *.jpg files in the directory tree
find . -type f -iname "*.jpg" -ls | awk 'BEGIN {print "0"}; {print $7, "+"}; END {print "p"}' | dc
Recursively changes group ownership of every folder in a current directory to the name of that folder.
find . -type d | sed -e 's/^\.\///g' -e 's/^\./avoid/g' | grep -v avoid | awk '{print $1"\t"$1}' | xargs chgrp
Get the processor's addressing bus width from the output of "lshw", ie. "64 bits".
lshw -class cpu|grep "^ width"|uniq|awk '{print $2}'
Print unique lines in "file1" compared to "file2" in the order they appear
comm -23 <(sort file1) <(sort file2)|grep -f - file1
Write the last line of "$file" to standard output and remove it from "$file"
tail -n 1 "$file" | tee >
Run ./yourProgram without address space randomization, reporting actual machine type.
setarch `uname -m` -R ./yourProgram
Find files and directories newer than CompareFile under current directory
find . -newer CompareFile -print
Find files owned by no group
find / -nogroup
display ten files in the tmp directory
find /tmp | head
display all the regular/normal files in the home folder that have been modified in the last 1 day
find ~/ -daystart -type f -mtime 1
Find all files in the home directory with open permissions
find ~ -perm 777
Find all regular files that start with stat
find . -type f –iname stat*
List each subdirectory name composing the current working directory
pwd | cut -f 1- -d\/ --output-delimiter=$'\n'
Find all foo.mp4 files in the current directory tree and print the pathnames of their parent directories
find . -name foo.mp4 -exec dirname {} \;
Overwirte file '/path/to/your/file' with random content, then overwrite with zeroes, and remove, showing progress while execution.
shred -v -n 1 -z -u /path/to/your/file
Delete all files with '.old' extension under current directory tree
find . -name “*.old” -print | xargs rm
Find all regular files named postgis-2.0.0 under current directory
find . -type f -name "postgis-2.0.0"
find all the files in the home folder which have been modified in the last 24 hours
find $HOME -mtime -1
Search /var for files matching regular expression '.*/tmp/.*[0-9]*.file'
find /var -regex '.*/tmp/.*[0-9]*.file'
Recursively changes group ownership of everything within '.git' to 'git'.
chgrp -R git .git
Search for all files in the current directory recursively whose names begin with "Linkin Park"
find . -name "Linkin Park*"
display the list of all the normal files excluding hidden files which have been accessed in the last 500 days
find . -type f -not -name ‘.*’ -mtime +500 -exec ls {} \;
Change the owner of all files in "/empty_dir/" to "root" using at most 10 files at a time
ls /empty_dir/ | xargs -n10 chown root
Find all the files/directories under user's home directory that do not belong to the user $USER
find ~ ! -user ${USER}
find all files in current folder which have been accessed exactly 10 minutes ago
find . -amin 10
Search for '“foobar”' in all files starting with '‘' and ending with '’' and contain '.' in their names in the entire filesystem and display only the matched files
find / -name ‘*.*’ -exec grep -il “foobar” {} \;
Gets domain name from dig reverse lookup and save in variable 'go'.
go=$
Print '-exec is an action so an implicit -print is not applied' for every file/directory found by the name 'file' under current directory tree
find -name file -exec echo '-exec is an action so an implicit -print is not applied' \;
Remove files in the current directory tree modified more than 31 days ago recursively
find . -type f -mtime +31 -print0 | xargs -0 -r rm -f
add read,write permissions to all the files in the current folder which have the permission 600
find . -perm 600 -print | xargs chmod 666
List all cron jobs which contain "word".
crontab -l | grep 'word'
Find how many directories are in a path
find . -type d -exec basename {} \; | wc -l
Print only common file names in sorted listings of directory 'dir1' and 'dir2'
comm -1 -2 < <
Display environment variable "_" of the current shell
set | grep "^_="
Prefix all files and directories in the current directory with "Unix_" if the files contain no whitespace or subdirectories
for FILENAME in *; do mv $FILENAME Unix_$FILENAME; done
Find all regular files that contain 'linux' (case insensitive) in their names under '/root' directory tree
find /root -type f -iname "*linux*"
search for the file, filename.txt in the folder /home
find /home -name filename.txt
Split "/usr/bin/cat" into 10000 files of about equal size
split -n 10000 /usr/bin/cat
Find all files/directories in entire file system that have "write" bit set for either the owner, the group, or others
find / -perm /a+w
Go into the first directory whose name contains 1670
cd `ls -d */ | grep 1670`
Create script filesPermissions.sh that restores the original permissions of the regular files in the current directory tree
find . -type f | xargs stat -c "%a %n" | awk '{print "chmod "$1" "$2}' > ./filesPermissions.sh
Find all *.c files under and below the current directory that contain "wait_event_interruptible"
find . -name \*.c -print0 | xargs -0 grep wait_event_interruptible /dev/null
display all the files in the file system which are changed a minute ago
find / -newerct '1 minute ago' -print
Process all files matching pattern 'file*' and residing in the xargstest/ directory tree with script `myscript.sh'
find xargstest/ -name 'file*' -print0 | xargs -0 myscript.sh
Find all files that belongs to group 'root' under / directory and show a few lines of output from the beginning
find / -group root | head
Delete characters in columns 36 through 40 from the output of "finger"
finger | sed 's/\...../\1/'