nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all *.sql files in maximum 1 level down the current directory, process it with sed and then send the output to a mysql command
find -maxdepth 1 -name '*.sql' -exec cat '{}' \; | sed -e 's/ , );/1,1);/g' | mysql -D ootp
Print a count of all unique entries in "ips.txt" with the most frequent results at the top
sort ips.txt | uniq -c | sort -bgr
Copy loadable kernel module "mymodule.ko" to the drivers in modules directory matchig current kernel.
sudo cp mymodule.ko /lib/modules/$(uname -r)/kernel/drivers/
Remove all files and directories in the current directory by answering with "y" to all prompts
yes | /bin/rm -i *
find files which full path name is /tmp/foo/bar under foo directory and print
find foo -path /tmp/foo/bar -print
Find all files/directories under current directory that were accessed less than 1 day ago
find . -atime -1 -print
Gets string with MAC addess of network interface eth0.
ifconfig eth0 | grep HWaddr
find all the files in the entire file system whose size is greater than 20MB
find / -type f -size +20000k
copy the file header.shtml to those dirs
find dir1 dir2 dir3 dir4 -type d -exec cp header.shtml {} \;
Report file system containing path-to-file disk usage human-readable.
df -h path-to-file
find all the png files in current folder which are present in the pattern list file "search.txt"
find . -name '*.png' | grep -f <(sed s/^/[0-9]_[0-9]_[0-9]_/ search.txt)
run ls command on files found
find . -name "*.pl" -exec ls -ld {} \;
Print the MD5 message digest of "/path/to/destination/file"
md5sum /path/to/destination/file
Set permissions for files in `foldername' to 777
find foldername -exec chmod a+rwx {} ";"
Print last day of April, 2009
cal 4 2009 | tr ' ' '\n' | grep -v ^$ | tail -n 1
Calculates process depth of process with id $processid, and stores it in a 'depth' variable.
depth=$
Find all php files in current directory and delete lines matching the regex '<\?php \/\*\*\/eval(base64_decode(.*));.*\?>' in those files
find . \( -name "*.php" \) -exec grep -Hn "<\?php /\*\*/eval(base64_decode(.*));.*\?>" {} \; -exec sed -i '/<\?php \/\*\*\/eval(base64_decode(.*));.*\?>/d' {} \;
find all the files ending with ".sh" in the folder /dir excluding those wth the names foo and bar.
find /dir \( -name foo -prune \) -o \( -name bar -prune \) -o -name "*.sh" -print
Display a detailed listing of the current directory, pausing for user input after each page.
ls -l | more
Change permissions of directory "/home/sshtunnel/" to 555
chmod 555 /home/sshtunnel/
Find the file whose inode number is 1316256
find . -inum 1316256
Find all files/directories named 'articles.jpg' under 'images' directory tree
find images -name "articles.jpg"
find all the "passwd" files in the entire file system
find / -iname passwd
Split "infile" into 2 files of about equal size
split -n2 infile
Look for any files that have not been modified in the last two days
find -mtime +2
Recursively changes group ownership of everything within a '/path/to/repo' to 'GROUP'.
chgrp -R GROUP /path/to/repo
Find only files under /etc with the size of 100k-150k
find /etc -size +100k -size -150k
set alias "go" for command 'GOPATH=$ go'
alias go='GOPATH=$ go'
Search the current directory tree for all image files
find . -type f -regex ".*\.\(jpg\|jpeg\|gif\|png\|JPG\|JPEG\|GIF\|PNG\)"
Move all hidden files in "/path/subfolder/" to "/path/"
mv /path/subfolder/.* /path/
Find all *.sql files in maximum 1 level down the current directory, process it with sed and then send the output to a mysql command
find . -maxdepth 1 -name '*.sql' -exec "sed -e 's/ , );/1,1);/g' '{}' | /usr/bin/mysql -D ootp" \;
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
Gets IP addresses of all active network interfaces.
ifconfig | grep -oP ".*?"
find all the files in current directory of size exactly 6MB.
find . -size 6M
Finds file 'Subscription.java' and changes to containing folder.
cd $(find . -name Subscription.java | xargs dirname)
Report total file systems disk usage in 1T blocks.
df --total -BT | tail -n 1
Remove the files or directories 'bin/node', 'bin/node-waf', 'include/node', 'lib/node', 'lib/pkgconfig/nodejs.pc' and 'share/man/man1/node.1'
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
Create an archive named newArch from the contents of ./test directory
find ./test -printf "././%f\n"| cpio -o -F newArch
Print unique list of who is logged in and the time of login formatted in columns
who -su | sort | uniq | column
Find all regular files under $FOLDER directory tree that start with '".' and end with '"' in their names and were modified in less than $RETENTION days excluding the files whose contents match one of the regular expressions defined per line in file $SKIP_FILE
find ${FOLDER} -type f ! -name \".*\" -mtime -${RETENTION} | egrep -vf ${SKIP_FILE}
List all directories of the $topdir directory tree that contain a Makefile and at least one .py file
find "$topdir" -name '*.py' -printf '%h\0' | xargs -0 -I {} find {} -mindepth 1 -maxdepth 1 -name Makefile -printf '%h\n' | sort -u
Run sed command "s#\\#\1/home/$/bin:~/\.local/bin:\2#" on "~/.zshrc" where "$" is replaced with the current user name
sed -i "s#\\#\1/home/$/bin:~/\.local/bin:\2#" ~/.zshrc
Select everything selected by * without descending into any directories
find * -maxdepth 0
Print flow of random data, showing all non-printing characters
cat -v /dev/urandom
Cuts off last two parts from the path $dir, and deletes resulted folder if empty.
rmdir "$(dirname $(dirname $dir))"
Find all files in maximum 1 level down the current directory that were modified less than 1 day ago from today
find -maxdepth 1 -type f -daystart -mtime -1
Searches the manual page names and descriptions by 'disk' keyword.
apropos disk
Run the PHP script 'yourscript.php', making it immune to SIGHUP signals.
nohup php -f 'yourscript'.php
Delete all files named 'core' under current directory
find . -name "core" -exec rm -f {} \;
Immediately exit the shell if a command fails
set -e
Save the absolute path of the current script to variable "SELF"
actual_path=$
Find root's files in the current directory tree
find ./ -user root
login as user YOUR_USER
su - YOUR_USER
Search the XML files from directories /res/values-en-rUS and /res/xml for string "hovering_msg"
find /res/values-en-rUS /res/xml -iname '*.xml' | while read file; do grep -i "hovering_msg" "$file"; done
Delete all empty directories in minimum 1 level down the directory 'directory'
find directory -mindepth 1 -type d -empty -delete
Find files owned by no group
find / -nogroup
find all the normal/regular files in current directory and display file names with new line as delimiter
find . -type f -exec printf '%.0sbla\n' {} +
Find all *.txt files under / and print their sizes and paths
find / -name '*.txt' -exec du -hc {} \;
Calculate the total amount of memory usage of the current user
alias memu="ps -u $ -o pid,rss,command | awk '{print \$0}{sum+=\$2} END {print \"Total\", sum/1024, \"MB\"}'"
Create a symbolic link named the basename of "$file" to "$file"
ln -s $file `basename $file`
find all the files in the current folder which have not been modified in the last 90 days and force delete them
find . -mtime +90 -type f -exec rm -f {} \;
Search for file "file" between level 2 and 3 of the directory tree
find -mindepth 2 -maxdepth 3 -name file
Write 200 lines of "this is the text I want to add to a file" to myFile.txt
yes "this is the text I want to add to a file"|head -200>myFile.txt
Search the /mnt/raid/upload directory tree for files that have not been modified within the last 5 days
find /mnt/raid/upload -mtime +5 -print
List all the .c files under the current directory and below in a 3 column format
find . -name "*.c" | xargs -n3
Truncate all non-empty regular files under the current directory
find . -type f -maxdepth 1 -not -empty -print0 | xargs -0i cp /dev/null {}
Print fourth column of data from text file "file" where columns separated by one or more whitespace.
tr -s ' ' < file | cut -d' ' -f4
find js file which name is not 'glob-for-excluded-dir' under current directory.
find . -name '*.js' -\! -name 'glob-for-excluded-dir' -prune
Find all files under $d directory (no sub-directories) that are executable by owner and print only their names
find $d -maxdepth 1 -perm -100 -type f | sed 's#.*/##'
Find recursively the latest modified file in the current directory
find . -type f -print0 | xargs -0 ls -ltr | tail -n 1
Print "y" for each line in "file2.txt" found in "file1.txt" and a blank newline otherwise
comm -2 file1.txt file2.txt | awk -F'\t' '{print (NF==2?"y":"")}'
list complete path name to process associated with pid "$1"
find /proc/$1/exe -printf '%l\n'
prints last part of a logfile since timestamp 423
tac file.log | awk '{ if ($1 >= 423) print; else exit; }' | tac
Find all files/directories under mnt/naspath that were modified in last 24 hours, calculate the total size and redirect the result to /tmp/size.log file
find /mnt/naspath -mtime 0 -print0 | du --files0-from=- -hc | tail -n1 >> /tmp/size.log
Enables shell option 'direxpand'.
shopt -s direxpand
filter output of bind -p by regex
bind -p | grep -a forward
Counts the number of lines in each *.swift or *.mm file in a git repository, escaping any space in filename.
git ls-files | sed 's/ /\\ /g' | grep -E "\.*" | xargs wc -l
Print the ping time number only of a single request to "8.8.8.8"
ping -c 1 8.8.8.8 | awk 'FNR == 2 { print $ }' | cut -d'=' -f2
find all regular files in current directory and replace the word searc to replace in them.
find . -type f -exec sed -i 's/searc/replace/g' {} \;
Find files in the /var/log folder which were modified between 60 minutes and 10 minutes ago
find /var/log/ -mmin -60 -mmin +10
Search directory foo for files containing "/tmp/foo/bar" in their full names
find foo -path /tmp/foo/bar -print
Find all *.xml.bz2 files under current directory
find . | grep ".xml.bz2$"
Removes all files from current folder but 5 newest ones, filtering out directories from initial search.
ls -tp | grep -v '/$' | tail -n +6 | xargs -d '\n' rm --
Search the current directory tree for files and directories whose names do not end in "exe" and "dll"
find . | grep -v '(dll|exe)$'
Force delete all jpg files in current directory which are less than 50KB and do not search in the sub directories
find . -maxdepth 1 -name "*.jpg" -size -50k | xargs rm -f
Find all the files in entire file system with the extensions txt or doc, as well as any file larger than 5MB in size
find / \( -name '*.txt' -o -name '*.doc' -o -size +5M \)
recursively change owner of the directory /usr/local/lib/node_modules/ to the current user
sudo chown -R $USER /usr/local/lib/node_modules
Search the current directory for PHP files
find . -type f -name "*.php"
Merge colon-separated information from file1 and file2 where first field of both files matches
join -t: <(sort file1) <(sort file2)
find all the html, javascript and text files in the current folder
find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt"
Monitor 3 specific process IDs: 18884, 18892, and 18919
top -p 18884 -p 18892 -p 18919
Print unique lines of sorted file "a" and "b" and remove leading tabs
comm -3 a b | sed 's/^\t//'
Find any hidden regular files in the current directory and its sub-directories that were modified after .cshrc was last modified.
find . -type f -name ".*" -newer .cshrc -print
find all the empty directories in current folder and delete them
find ./ -empty -type d -delete
Perform a default Plesk configuration
find /var/www/vhosts/*/httpdocs -type f -iwholename “*/wp-includes/version.php” -exec grep -H “\$wp_version =” {} \;
finds all directories named CVS, and deletes them and their contents.
find . -type d -name CVS -exec rm -r {} \;
Find all files/directories under current directory and run <script> for each of them
find -exec <script> {}\;
Create directorie(s) 'some/path' as required in the current directory
mkdir -p ./some/path
Request DNS record for domain 'dragon-architect.com' with tracing and additional section, and extract third block of text, separated between two new lines.
dig +trace +additional dragon-architect.com | awk 'NR==3' RS="\n\n"
Mount partition with label "WHITE" on "/mnt/WHITE" with read and write permission and have it accessible by user and group "test"
mount -L WHITE /mnt/WHITE -o rw,uid=test,gid=test