nl_command
stringlengths 14
387
| bash_code
stringlengths 0
532
|
---|---|
display the number of lines in all the php files in the current folder | 1 down vote wc -cl `find . -name "*.php" -type f` |
Find files and directories whose owner is daniel | find . -user daniel |
Replace all instances of "STRING_TO_REPLACE" with "STRING_TO_REPLACE_IT" in file "index.html" and make a backup with suffix "bak" on OSX | sed -i bak -e s/STRING_TO_REPLACE/REPLACE_WITH/g index.html |
change the extension of all the ".abc" files in the folder "/the/path" to ".edefg" and do not change in the sub directories | find /the/path -depth -name "*.abc" -exec sh -c 'mv "$1" "${1%.abc}.edefg"' _ {} \; |
find the file "filename.txt" in the usr folder | find /usr -name filename.txt -print |
Execute /usr/bin/find with $* arguments where current directory is the first argument | /usr/bin/find ./ $* |
create directory subdirectory | mkdir subdirectory |
Records the number of occurences of 'needle' in the array 'haystack' into the variable 'inarray' | inarray=$ |
Create intermediate directories as required directory{1..3} and subdirectory{1..3} and directories subsubdirectory1 and subsubdirectory2 | mkdir -p directory{1..3}/subdirectory{1..3}/subsubdirectory{1..2} |
Search for all files in the current directory recursively whose names contain "linkin park", ignoring the case | find . -iname "*linkin park*" |
Change permissions to u=rwx,g=rx,o= for all directories inside the current directory tree | find . -type d -exec chmod u=rwx,g=rx,o= '{}' \; |
List only the non-hidden empty files only in the current directory. | find . -maxdepth 1 -empty -not -name ".*" |
search for the ip "192.168.1.5" in all the files in /etc folder | find /etc/ -iname "*" | xargs grep '192.168.1.5' |
Recursively removes all files like '_*' and '.DS_Store' from /var/www/html/ folder. | rm /var/www/html/**/_* /var/www/html/**/.DS_Store |
Rename all *company* files/directories under current directory to *nemcompany* files/directories | for f in `find -name '*company*'` ; do mv "$f" "`echo $f | sed s/company/nemcompany/`" ; done |
Find all *fink* files/directories in entire file system | find / \( -type f -or -type d \) -name \*fink\* -print |
Add a cron job to existing list, without removing existing ones, ro tun "scripty.sh" at 2:01 am, 3rd day of april , if that day happens to be a friday . | cat < < | crontab - |
Print the list of non-hidden directories in the current directory | find -type d -maxdepth 1 ! -name ".*" -printf "%f\n" |
find all png files in the current folder | find . -type f -name '*.png' |
Print content of all files found regarding seach options '[whatever]' | find [whatever] -exec cat {} + |
Display IP address and login time of the current user's session | last -i | grep $ | grep 'still logged in' |
Print a count of case insensitive duplicate filenames in the current directory | ls -1 | tr '[A-Z]' '[a-z]' | sort | uniq -c | grep -v " 1 " |
Recursively change the owner and group of all files in "public_html" to "owner" | chown -R owner:owner public_html |
Save the current user name and inode number of "/home" into bash array variable "var" | var=( $ ) |
Search the entire file hierarchy for files ending in '.old' and delete them. | find / -name "*.old" -delete |
Find all *.m4a files under /home/family/Music directory | find /home/family/Music -type f -name '*.m4a' -print0 |
Print a sorted list of regular files from directory tree /folder/of/stuff | find /folder/of/stuff -type f | sort |
Search the regular files from directory tree 'folder_name' for "your_text" | find folder_name -type f -exec grep your_text {} \; |
search for all the perl files in the folder /nas/projects/mgmt/scripts/perl which have been modified 8-10 days ago. | find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl" |
search for regular files in the current folder which path is not "./.*" and not "./*/.*" | find ./ -type f -name "*" ! -path "./.*" ! -path "./*/.*" |
ERROR - this is for DOS | ping -n 1 %ip% | find "TTL" |
Find '*prefs copy' files under /mnt/zip and delete them ensuring white space safety | find /mnt/zip -name "*prefs copy" -print0 | xargs> -0 rm |
Get a detailed listing of all symbolic links in /usr/bin starting with "z" | find /usr/bin -type l -name "z*" -exec ls -l {} \; |
display all files in the current folder that have been modified in the last 24 hours whose name has only 1 letter | find . -name \? -mtime -1 |
Set the 'xtrace' shell variable | set -x |
Remove all *bak files under current directory with confirmation prompt | find . -name '*bak' -exec rm -i {} \; |
Delete all in the current directory tree | find . -delete |
Print 'Empty dir' if $some_dir is empty, otherwise print 'Dir is NOT empty' | if find "`echo "$some_dir"`" -maxdepth 0 -empty | read v; then echo "Empty dir"; else "Dir is NOT empty" fi |
List all environment variables whose name starts with PATH, showing the name and value of each one. | env | grep ^PATH |
Search the current directory tree for .log files containing the string "The SAS System" on the first line | find . -name '*.log' -type f -readable ! -size 0 -exec sed -n '1{/The SAS System/q0};q1' {} \; -print |
Replace all instances of "string" with "longer_string" in file "input.txt" and re-align | cat input.txt | sed 's/string/longer_string/g' | column -t |
Puts working directory into clipboard, stripping newlines | printf $ | pbcopy |
Find files on the system bigger than 50MB but smaller than 100MB | find / -type f -size +50M -size -100M |
Find directories that are directly under $workspace_ts directory (no-subdirectories) and were modified more than 30 days ago | find $workspace_ts -mindepth 1 -maxdepth 1 -type d -mtime +30 -print |
Convert the first 16 characters in "/dev/random" to a single hexadecimal value | head /dev/random -c16 | od -tx1 -w16 | head -n1 | cut -d' ' -f2- | tr -d ' ' |
Remount "/dev/stl12" on "/system" as read only | mount -o ro,remount /dev/stl12 /system |
Show file type information for all regular files under '/home' directory tree | find /home -type f -exec file {} \; |
Archive "_vimrc" to "~/.vimrc" suppressing non-error messages and compressing data during transmission | rsync -aqz _vimrc ~/.vimrc |
Compare the files in 'FOLDER1' and 'FOLDER2' and show which ones are indentical and which ones differ | find FOLDER1 -type f -print0 | xargs -0 -I % find FOLDER2 -type f -exec diff -qs --from-file="%" '{}' \+ |
find all files the current folder which have not been accessed in the last 7 days and which are bigger than 20KB | find . -atime +7 -size +20480 -print |
Find all files matching pattern '.#*' in the current directory tree and execute "foobar" for each of them with the file name as an argument | find . -iname '.#*' -print0 | while read -r -d '' i; do foobar "$i"; done |
Find all *.log files under current directory that contain the string "Exception" | find . -name '*.log' -mtime -2 -exec grep -Hc Exception {} \; | grep -v :0$ |
Find all aliencoders.[0-9]+ files/directories under /home/jassi/ directory | find /home/jassi/ -name "aliencoders.[0-9]+" |
Find all *.log files under path/ that do not contain "string that should not occur" | find path/ -name '*.log' -print0 | xargs -r0 -I {} bash -c 'grep -q "string that should not occur" "{}" || echo "{}"' |
Find all files under /myfiles with read-write access for others | find /myfiles -type f -perm -o+rw |
Read a line from standard input into the variable "yn" with the prompt "Do you wish to install this program?" | read -p "Do you wish to install this program?" yn |
Search /path/to/your/directory for *.avi and *.flv files | find /path/to/your/directory -regex '.*\.\(avi\|flv\)' |
Find all Name* files under ../../$name-module and rename them by replacing 'Name' with $Name (will be expanded in the current shell) in their names | find ../../$name-module -print0 -name 'Name*' -type f | xargs -0 rename "s/Name/$Name/" |
Show the number of lines for each PHP file in the current directory tree | find . -type f -name "*.php" -exec wc -l {} +; |
Search the files from the current directory tree for text "documentclass" | find . -type f -print0 | xargs -0 grep -H 'documentclass' |
display all file in the folder /dir/to/search except ".c" files | find /dir/to/search/ -not -name "*.c" -print |
search for regular files in the current folder which path is not "./.*" and not "./*/.*" | find ./ -type f -name "*" ! -path "./.*" ! -path "./*/.*" |
Find all the files/directories in '/path/to/files' directory tree which have not been modified in the last 2 hours | find "/path/to/files" -mmin +120 |
Prints all Saturday days of a current month. | cal -h | cut -c19-20 |
Move "caniwrite" without clobbering into "/usr/local/bin" | mv -nv caniwrite /usr/local/bin |
Copies all files under the current folder like "file.ext" with "FooBar" in the path to the root of the current folder, preserving mode, ownership and timestamp attributes. | find . -name "file.ext"| grep "FooBar" | xargs -i cp -p "{}" . |
Print a line of 100 random characters either "." or " " | cat /dev/urandom | tr -dc '. ' | fold -w 100 | head -1 |
find all files in the current folder which are bigger than 10bytes | find . — size +10 -print |
Search "whatyousearchfor" in history and print 3 lines before and 4 lines after | history | grep -A 4 -B 3 whatyousearchfor |
Print all lines in file that do not match "pattern" | sed -n '/pattern/!p' file |
Execute awk script "script.awk" on "File2" and "File1" and format output as a table | awk -f script.awk File2 File1 | rev | column -t | rev |
Extract any line in "f1" or "f2" which does not appear in the other | comm -3 < < |
Search in current directory downwards all files whose size is greater than 10 bytes . | find . -size +10c -print |
Force create a symbolic link named "$lines" to "$c" without dereferencing "$lines" | ln -sfn "$c" "$lines" |
find all the text files in the current folder and do not search in somedir, bin directories | find . -name somedir -prune , -name bin -prune -o -name "*.txt" -print |
Print the help message for tree | tree --help |
Search for files greater than 20MB under your home directory | find ~ -size +20M |
calculate the disk usage for all the files which have been modified in the last 24 hours in ~/tmp folder and display the file sizes | find ~/tmp -mtime 0 -exec du -ks {} \; | cut -f1 |
find all files in the folder "myfiles" which have not been accessed in the last 30*24 hours | find /myfiles -atime +30 |
Print a listing of the /usr/local/etc/rc.d directory tree | find /usr/local/etc/rc.d -type f | awk -F/ '{print $NF}' |
Print "$somedir is empty" if $somedir is empty | find "$somedir" -maxdepth 0 -empty -exec echo {} is empty. \; |
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 "$( which "$0" )" )/lib/B" |
Print first word of lines unique for 'file1' file | grep -o '^\S\+' <(comm file1 file2) |
Find and remove multiple files such as *.mp3 or *.txt | find . -type f -name "*.mp3" -exec rm -f {} \; |
Find all files under ./lib/app and redirect their sorted list to myFile | find ./lib/app -type f | sort | tee myFile |
Find all regular files under current directory tree that match the regex 'tgt/etc/*' in their paths | find . -type f -name \* | grep "tgt/etc/*" |
Find all *.txt files/directories under current directory terminating their names/paths with null character | find . -name '*.txt' -print0 |
Search the /var/www/ tree for files not owned by user `apache' | find /var/www ! -user apache -print0 | xargs -0 |
Mathematically sum a column of numbers in "FileWithColumnOfNumbers.txt" | cat FileWithColumnOfNumbers.txt | xargs ruby -e "puts ARGV.map.inject" |
Find all files/directories named 'query' under current directory tree | find -name "query" |
Print a list of JPG files residing in the current directory tree | find . -name “*.jpg” |
find setuid files and directories writing the details to /root/suid.txt , and find large files writing the details to /root/big.txt, traversing the filesystem just once | find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \ \( -size +100M -fprintf /root/big.txt '%-10s %p\n' \) |
Gets MAC addresses of all active network interfaces. | ifconfig | awk '$0 ~ /HWaddr/ { print $5 }' |
Run checksums recursively from the current directory, and give back the filenames of all identical checksum results | find ./ -type f -print0 | xargs -0 -n1 md5sum | sort -k 1,32 | uniq -w 32 -d --all-repeated=separate | sed -e 's/^[0-9a-f]*\ *//;' |
Find all *-* files under current directory | find . -type f -name '*-*' |
ssh into "ssh.myhost.net" as user "myusername" and run command "mkdir -p $2" | ssh [email protected] "mkdir -p $2" |
Delete all ".DS_Store" files/directories under test directory | find test -name ".DS_Store" -delete |
Set 644 permission to all regular files under /path | find /path -type f -exec chmod 644 {} +; |
Save the current user name in variable "myvariable" | myvariable=$(whoami) |
Print the minimum transmission time of 10 ping requests to "google.com" from cygwin | ping google.com -n 10 | awk '/Minimum =/ { sub; print $3 }' |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.