nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all files/directories with '.log' extension whose names start with 'app-', have been modified in the last 5 minutes and show the first one found
find /var/log/crashes -name app-\*\.log -mmin -5 -print | head -n 1
Use 'top' to monitor the newest instance of ProgramName.
top -p "$"
Display the files/directories under current directory tree matching the regex '/$prefix$ypatt' where $prefix and $ypatt expands in the current shell
find . -print | grep "/${prefix}${ypatt}"
Search the entire system for SUID or SGID files
find / -path /proc -prune -o -type f -perm +6000 -ls
find all files in the current folder which are of size 0 bytes.
find . -type f -empty
change cgi files to mode 755 under htdocs or cgi-bin directories
find htdocs cgi-bin -name "*.cgi" -type f -exec chmod 755 {} \;
find all the files in the current directory and print them excluding those that have the name SCCS.
find . -print -o -name SCCS -prune
Find all the files recursively in directories or files taken from the glob pattern /tmp/test/* that have been modified today
find /tmp/test/* -mtime -0
Find all regular files in the current directory tree ignoring GIT and SVN directories
find . \( -type d -regex '^.*/\.\$' -prune -false \) -o -type f -print0
Show all previously typed shell commands, waiting for user interaction after each page of output.
history | more
create directory /etc/cron.15sec
mkdir /etc/cron.15sec
Print equal lines in compressed files "number.txt" and "xxx.txt"
comm -12 < <
List all leaf directories under current directory
for dir in $; do [[ ! $prev =~ $dir ]] && echo "$dir" ; prev="$dir"; done
search for mp3 files in the folder /mp3collection which are smaller than 5MB
find /mp3collection -name '*.mp3' -size -5000k
Change the permissions of every directory in the current directory and all files and directories within them to 700
find . -maxdepth 1 -type d -exec chmod -R 700 {} \;
find the file "dateiname" in the entire file system
find / -iname "Dateiname"
Delete all '-' character from $1 and save the resultant string to variable 'COLUMN'
COLUMN=`echo $1 | tr -d -`
find all the text files in the current folder starting with "somefiles-"
find . -name "somefiles-*-.txt" -type f
SSH login in 'middle.example.org' via port 2222 as user 'deviceuser' using a private key file './device_id.pem'
ssh -i ./device_id.pem [email protected]:2222
Print file name without extension assuming there is only one dot in the file name.
echo "$FILE" | cut -d'.' -f1
Print all files on the system owned by group `name_of_group'
find / -group name_of_group
Print flow of random data, showing all non-printing characters
cat -v /dev/urandom
Display smbios/DMI information, pausing for user interaction between pages of output.
dmidecode | more
extract /path/to/my_archive.tar.xz to /path/to/extract and preserve permissions.
tar xpvf /path/to/my_archive.tar.xz -C /path/to/extract
Prints long listing of content in a root folder, including hidden files, with human-readable sizes, and stores output to '/root/test.out' file.
sudo ls -hal /root/ | sudo tee /root/test.out > /dev/null
Look for SUID files and directories
find / -perm +4000
Search for 'keyword' in all javascript files under current directory tree excluding all paths that includes the directory 'node_modules'
find ./ -not -path "*/node_modules/*" -name "*.js" | xargs grep keyword
Execute "ps -mo pid,tid,%cpu,psr -p \`pgrep BINARY-NAME\`" every half second displayed with no title and highlighting the differences
watch -tdn0.5 ps -mo pid,tid,%cpu,psr -p \`pgrep BINARY-NAME\`
find all the files ending with ".sh" in the folder /dir excluding those wth the names foo and bar.
find /dir \ -o \ -o -name "*.sh" -print
Verbosely compresses all files on fifth and sixth depth level keeping original files in place.
bzip2 -kv */*/*/*/*/*
Find all files whose names end with "macs" in and below the current directory
find -name '*macs'
Recursively finds all files and prints all strings with 'text-to-find-here' from that files, preceding matched string with filename.
find ./ -type f -exec grep -H 'text-to-find-here' {} \;
Mount image "test" to loop device "/dev/loop0"
sudo mount -o loop /dev/loop0 test
Find all files under current directory whose status was changed less than 3 days ago, sort them and show last 5 lines of output with only their paths
find . -type f -ctime -3 -printf "%C@ %p\n" | sort | tail -n 5 | sed 's/[^ ]* \(.*\)/\1/'
display all the file in the folder /home/david/ which start with the word "index"
find /home/david -iname 'index*'
Compare files in "/tmp/dir1" and "/tmp/dir2", treat absent files as empty and all files as text, and print 3 lines of unified context
diff -Naur dir1/ dir2
list regular files under the user's home directory that are over 100KB and have not been accessed in over 30 days.
find $HOME -type f -atime +30 -size 100k
display a long list of all the files that are bigger than 10KB in current folder
find . -size +10k -exec ls -l {} \;
Move each of the 'm?' directories in current directory 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 . -name 'm?' -type d -exec mv '{}' '{}.mbox' ';' -exec mkdir '{}.mbox/Messages' ';' -exec sh -c 'mv {}.mbox/*.emlx {}.mbox/Messages' ';'
Search for files that are at least 100MB
find / -size +100M
Print the names of all regular files in the current directory tree
find . -type f -exec echo {} \;
using exec in find command to dispaly the searched files
find . ... -exec cat {} \; -exec echo \;
Find all files under $x directory and set read-write permission for owner and group and no permission for other for those files
find ${x} -type f -exec chmod ug=rw,o= '{}' \;
Print last day of April, 2009
cal 4 2009 | tr ' ' '\n' | grep -v ^$ | tail -n 1
search for all the files in the current directory which belong to the user "xuser1" and change the owner ship of them to "user2"
find . -user xuser1 -exec chown -R user2 {} \;
Find all /path/to/check/* regular files without descending into any directory
find /path/to/check/* -maxdepth 0 -type f
Installs package "nodejs" answering 'yes' on all questions.
yum install -y nodejs
find all files that belong to root user
find . -uid 0 -print
Find all files/directories under current directory tree that start with 'R' and end with 'VER' in their names and were modified more than 1 day ago
find . -name "R*VER" -mtime +1
delete all the files in the current folder
find . -print0 | xargs -0 rm
Print only common strings in content of files 'file1.sorted' and 'file2.sorted'
comm -1 -2 file1.sorted file2.sorted
find all the files in the file system which have read permission to the user and display the ten files
find / -perm /u=r | head
Print the list of regular files from the current directory that were last modified on November, 22
find . -maxdepth 1 -type f -newermt "Nov 22" \! -newermt "Nov 23" -exec echo {} +
Print continuous characters '/' and '\' randomly from /dev/urandom
grep -ao "[/\\]" /dev/urandom|tr -d \\n
Pipe 3 newlines to sshe-keygen, answering prompts automatically.
echo -e "\n\n\n" | ssh-keygen -t rsa
find all normal/regular files in the folder /some/dir and save the output to the file "somefile"
find /some/dir/ -type f > somefile
Find all directories named '.texturedata' under '/path/to/look/in/' directory tree
find /path/to/look/in/ -type d -name '.texturedata'
Display all available header information for the executable file of command "tail"
objdump -x `which tail`
Split "file.txt" into files of at most 20 lines each with a prefix "new"
split -l 20 file.txt new
find all the files that are modified exactly one day ago
find -daystart -mtime 1
Execute "chown -R ask:ask /www/askapache.com" in the background on server "askapache"
ssh askapache 'sh -c "( & )"'
Replace all newlines from standard input except the last with spaces
sed ':a;N;$!ba;s/\n/ /g'
Find all directories in the current one recursively which have the write bit set for "other"
find . -type d -perm -o=w
Count the number of files in the directory trees whose pathnames match pattern '/dev/sd*[a-z]'
find /dev/sd*[a-z] -printf . | wc -c
Connect via ssh to "your.server.example.com" and recursively copy directory "/path/to/foo" on this host to direcotry "/home/user/Desktop" on local host, using "blowfish" cipher algorithm.
scp -c blowfish -r [email protected]:/path/to/foo /home/user/Desktop/
kill all background processes
kill -INT $(jobs -p)
Prints last modified file in a current folder with modification time.
find . -type f -printf '%TY-%Tm-%Td %TH:%TM: %Tz %p\n'| sort -n | tail -n1
display the html, javascript and text files in the current folder
find . -type f \ -exec sh -c 'echo "$0"' {} \;
get the count of all the files that have been accessed in the last 30 days
find . -atime +30 -exec ls \; | wc -l
Find all directories under ~/code excluding hidden directories and replace all newlines with : in the output then remove the last :
find ~/code -type d -name '[^\.]*' | tr '\n' ':' | sed 's/:$//'
Find all .txt files under the current directory and below
find . -name '*.txt' -print0
Find all CDC* files under current directory that were accessed less than 1 day ago and delete the first and last lines from those files and count the number of lines in the output
find . -type f -name "CDC*" -ctime -1 -exec sed -i'' -e '1d' -e '$d' '{}' \ | wc -l
Print summary of new/missing files, and which files differ between /path/to/folder1 and /path/to/folder2, sorted alphabetically.
diff -rq /path/to/folder1 /path/to/folder2
Look in the current directory and below for all files whose names begin with either "my" or "qu"
find . \ -print
Write "hey hey, we're the monkees" to standard output and as input to to "gzip --stdout" saved to "my_log.gz"
echo "hey hey, we're the monkees" | tee /dev/tty | gzip --stdout > my_log.gz
Find regular files in the current directory tree that have all executable bits set
find -L . -type f -perm -a=x
Find directory "/some/dir" if it is empty
find /some/dir/ -maxdepth 0 -empty
find all the html files in current folder and replace old string with new string
perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`
Print unique lines of sorted file "second.txt" compared to sorted file "first.txt"
comm -13 first.txt second.txt
Search the current directory tree for regular files whose names end in ".shtml" or ".css"
find . -type f \
Decompress and extract 'archive.tar.gz' into '/destination'
gzip -dc archive.tar.gz | tar -xf - -C /destination
Prints what day it was 222 days ago
date --date="222 days ago" +"%d"
Copies file 'index.html' to each top-level directory in the current directory.
find . -mindepth 1 -maxdepth 1 -type d| xargs -n 1 cp -i index.html
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 \;
Remount "rfs" filesystem "/dev/stl12" on "/system" with read and write permission
mount -o rw,remount -t rfs /dev/stl12 /system
List all regular files in /var/www and below that have changed in the last 10 minutes
find /var/www -cmin -10 -type f -printf "%c %pn"
Find files and directories with group id 1003
find . -gid 1003
Search for "vid=123" in all compressed files found under "/my_home" matching "*log.20140226*"
zcat `find /my_home -name '*log.20140226*'`|grep 'vid=123'
Delete and count files in $DIR_TO_CLEAN that are older than $DAYS_TO_SAVE days
find "$DIR_TO_CLEAN" -mtime +$DAYS_TO_SAVE -exec bash -c 'printf "Total: %d\n" $#; rm "$@"' _ {} +
Copy all files unconditionally and directories in directory tree "myfiles" to "target-dir" preserving directory hierarchy and modification time
find myfiles | cpio -pmud target-dir
display all the files in the folder /mp3-collection which are bigger than 10MB or which start with the name "Metallica"
find /mp3-collection -name 'Metallica*' -or -size +10000k
Count the number of characters in the list of regular files from the current directory tree
find . -type f | xargs | wc -c
Prevent ssh from reading from standard input and execute "touch /home/user/file_name.txt" on "$R_HOST" as "$R_USER"
ssh -n $R_USER@$R_HOST 'touch /home/user/file_name.txt'
Removes first and last parts of path 'test/90_2a5/Windows' and prints the result.
echo 'test/90_2a5/Windows' | xargs dirname | xargs basename
Find all files/directories under current directory tree that contain '1' or 'k' in their names
find . -name "*[1k]*"
Find all .sql files in the current directory recursively and apply script "scriptname" to them
find . -name '*.sql' -exec scriptname {} +
Search the current directory tree for regular .mkv files
find . -type f -name "*.mkv"
Save absolute path of the script filename in variable "MY_PATH"
MY_PATH=$(readlink -f "$0")
Move all *.pdf.marker files and their corresponding *.pdf files under ${INPUT} to ${OUTPUT}
find ${INPUT}/ -name "*.pdf" -exec mv '{}' '{}'.marker ${OUTPUT} \;
Read the raw input of "/dev/input/mice" as hexadecimal bytes with 3 bytes per line
cat /dev/input/mice | od -t x1 -w3