nl_command
stringlengths 14
387
| bash_code
stringlengths 0
532
|
---|---|
Count the number of total files and folders under current directory tree | find . -print0 | tr -cd '\0' | wc -c |
Print the first line of every file matching pattern 'file?B' in the xargstest/ directory tree | find xargstest/ -name 'file?B' | sort | xargs head -n1 |
display all html files in current folder and replace some pattern in all these files | find -name "*.htm" | while read file; do sed "s|<title>sometext</title>|<title>${file##*/}</title>|g" -i $file; done |
Force decompress all files into '/etc' | gzip -d --force * /etc |
Find files/directories named 'photo.jpg' in the entire filesystem | find / -name photo.jpg |
Find all files/directories named 'file' without descending into directories with the same name under current directory tree | find -name file -prune |
Change the group of all directories under current directory tree to a group with the same name as the directory name | find . -type d | sed -e 's/\.\///g' | awk '{print $1, $1}' | xargs chgrp |
Find all files, starting from / but ignoring removable media, whose names end with ".rpm" | find / -xdev -name "*.rpm" |
Search all .c and .h files in the current directory tree for string "e" | find . -name "*.[ch]" -exec grep --color -aHn "e" {} \; |
find files which full path name is foo/bar under foo directory and print | find foo -path /tmp/foo/bar -print |
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 files and directories in the current directory recursively that contain spaces in their names | find . -name '* *' |
Find all directories in directory tree `httpdocs' | find httpdocs -type d |
Compress all files not ending in ".gz" in directory "$PATH_TO_LOGS" that were last modified more than "$SOME_NUMBER_OF_DAYS" days ago | find $PATH_TO_LOGS -maxdepth 1 -mtime +$SOME_NUMBER_OF_DAYS -exec sh -c "case {} in *.gz) ;; *) gzip '{}' ;; esac;" \; |
List subdirectories in the current directory | find . -maxdepth 1 -type d -exec ls -ld "{}" \; |
Compresses all '*.xml' files under current directory with 'bzip2' utility. | find -name \*.xml -print0 | xargs -0 -n 1 -P 3 bzip2 |
Remove the first 13 characters of each ".txt" filename in the "/tmp" directory tree and number the output | find /tmp -type f \( -name '*.txt' \) |cut -c14- | nl |
Find out all files owned by user vivek | find / -user vivek |
grep for the last occurrence of text between two tags | tac a | grep -m1 -oP '(?<=tag>).*(?=</tag>)' |
Print unique lines of sorted file "A.txt" compared to sorted file "B.txt" | comm -23 < < |
Delete all the files found in the current directory tree whose names begin with "heapdump" | find . -name heapdump* -exec rm {} \ ; |
find all the regular files in the current folder which have specific word in their name and force delete all these files and save the log to the file log_del.txt | find ./ -type f -name '*.c*' -print0 | xargs -0 rm -rf &>> log_del.txt |
Save the full path of command "oracle" to variable "path" | path=`which oracle` |
Search the current directory tree for regular files that were modified $FTIME days ago | find . -type f -mtime $FTIME |
Creates path as current folder path and folder that contains $0 file, and saves result in 'script_dir' variable. | set script_dir = `pwd`/`dirname $0` |
Wrap standard input to fit in 10 characters per line | fold -w 10 |
find all directory list which have empty list in /tmp directory | find /tmp -type d -empty |
Find all files whose names do not begin with "zsh" on ext3 file systems | find / -fstype ext3 -name zsh -ls 2> /dev/null |
Find all files/directories under current directory with 'foobar' (case insensitive) in their names and copy them to ~/foo/bar | find . -iname "*foobar*" -exec cp "{}" ~/foo/bar \; |
Search for the regex '^aaa$' in all *.txt files under current directory and count the number of matches | | sed 's/ /\n/g' | grep '^aaa$' | wc -l |
Print absolute path of "YOUR_PATH" | readlink -f YOUR_PATH |
Search the current directory recursively for MOV files | find . -iname *.mov |
Remove all files from the current directory tree whose names contain whitespaces | find . -name "* *" -exec rm -f {} \; |
Display a list of files with sizes in decreasing order of size of all the regular files under '/your/dir' directory tree that are bigger than 5 MB in size | find /your/dir -type f -size +5M -print0 | xargs -0 ls -1Ssh |
Search all .java files residing in the current directory tree and modified at least 7 days ago for string "swt" | find . -name '*.java' -mtime +7 -print0 | xargs -0 grep 'swt' |
Find files matching regular expression regexp | find . | xargs grep regexp |
Rename all .txt files to .bak in the current directory tree | find . -name "*.txt" | sed "s/\.txt$//" | xargs -i echo mv {}.txt {}.bak | sh |
Print only the line "foo///" given two empty directories foo and bar | find foo/// bar/// -name foo -o -name 'bar?*' |
Find all *.java files under current directory containing the string 'String' | find . -name "*.java" -exec grep "String" {} \; |
Remove all *.sql files in the $backup_path directory tree that were last modified more than 30 days ago | find $backup_path/* -name *.sql -mtime +30 -exec rm {} \; |
search the entire file system and save all the core file paths into a file | find / -name core -print | xargs echo > /tmp/core.log |
Counts lines in each of *.php files in current folder with subfolders and prints total count as well. | find . -name '*.php' | xargs wc -l | sort -r |
Send text "spawn daemon" and a newline character to the screen session | screen -r user -X stuff "spawn daemon$" |
Save the absolute path of the current script to variable "SELF" | SELF=`readlink /proc/$$/fd/255` |
Find all symbolic links under '/some/directory' tree | find /some/directory -type l -print |
Save hexadecimal byte 9 in binary file "file.moi" to variable "month" | month=$ |
Save actual working directory in variable "target_PWD" | target_PWD=$(readlink -f .) |
Remove all *.doc files from the current directory tree | find . -name '*.doc' -exec rm "{}" \; |
Set permissions to ug=rwx,o= for directories under the $d directory tree | find $d -type d -exec chmod ug=rwx,o= '{}' \; |
Make DNS lookup requests for domain list in file '/path/to/host-list.txt' | dig -f /path/to/host-list.txt |
List path/filename of all PHP files under current directory whose file type description or path/name contains "CRLF" | find . -type f -iname "*.php" -exec file "{}" + | grep CRLF |
find all the files which are of size 0 bytes. | find . -type f -empty |
Save the line number matching "}]" in lines starting with "item_1" to "item_2" in "itemlist.json" to variable "line_to_be_replaced" | line_to_be_replaced=`cat itemlist.json | nl | sed -n '/"item_1"/,/"item_2"/p' | grep -in "}]" | awk '{print $2}'` |
Save the list of all subdirectories of the current directory up to depth level 2 as "dirlist" | find -maxdepth 2 -type d -ls >dirlist |
Find all *.xml.bz2 files under current directory | find . -name \*.xml.bz2 |
Replace all occurrence of "subdomainA.example.com" with "subdomainB.example.com" in all files under /home/www and below | find /home/www -type f -print0 | xargs -0 sed -i 's/subdomainA.example.com/subdomainB.example.com/g' |
change owner of all files into current directory except files named as './var/foo*' to user www-data | find . -not -iwholename './var/foo*' -exec chown www-data '{}' \; |
Search directory tree `MyApp.app' for directories whose name is 'Headers' and delete them in an optimized way | find -d MyApp.app -name Headers -type d -print0 | xargs -0 rm -rf |
Read a single character from standard input and save to variable "y" | y=$ |
display all files in the current directory excluding those that are present in the directories whose name starts with "efence" and do not search in the sub directories | find * -maxdepth 0 -name "efence*" -prune -o -print |
Find all files/directories in current directory and execute myscript for each of them | find . -exec myscript {} \; |
Print all unique directory paths under "dir1" compared to "dir2" | comm -23 < < | sed 's/^\//dir1/' |
Prints name of a current shell binary file. | ls -l /proc/$$/exe | sed 's%.*/%%' |
find all the normal/regular files in the current folder which have been modified in the last 24 hours and display a long listing of them | find . -type f -mtime -1 -exec ls -l {} \; |
List all files in the current directory tree except for those in the ./src/emacs directory | find . -path './src/emacs' -prune -o -print |
Move all files and directories in the current directory to "$TARGET" excluding files matching "$EXCLUDE" | ls -1 | grep -v ^$EXCLUDE | xargs -I{} mv {} $TARGET |
Find directories in the /path directory tree whose names are 33 characters in length | find /path -type d -printf "%f\n" | awk 'length==33' |
find all the files in current folder which end with ".bak" or ".backup" which have not been accessed in the last 30 days and delete the files if they exist | find . -type f -atime +30 -exec csh -c 'if rm $1' '{}' ; |
search for all empty directories in the folder /home | find /home -type d -empty |
Display name and value of 'variable' if it exists. | env | grep '^variable=' |
Change to directory 'xyz' and resolve any symlinks in the resulting path, making the physical path the current one. | cd -P xyz |
List all files/directories under current directory matching the posix-egrep type regex ".+\.(c|cpp|h)$" in their names excluding the paths */generated/* and */deploy/* | find . -regextype posix-egrep -regex '.+\.(c|cpp|h)$' -not -path '*/generated/*' -not -path '*/deploy/*' -print0 | xargs -0 ls -L1d |
View history using "less" | history | less |
Remove ESC key bind | bind -r '\e' |
Find string "STRING" in files residing in the current directory tree, case insensitive | find . -type f -print | xargs grep -ni "STRING" |
Find all links to path/to/file | find -L -samefile path/to/file |
Save absolute path of "$path" that must exist along with all parents to variable "abspath" | abspath=$(readlink -e $path) |
Find the "*.foo" files in the current directory tree that are not under ".snapshot" directories | find . -name .snapshot -prune -o -name '*.foo' -print |
change owner and group of the current directory and all files into it to user and group andrew | chown -R andrewr:andrewr * |
Search for first match of the regex 're' in all *.coffee files under current directory | find . -name \*.coffee -exec awk '/re/ {print;exit}' {} \; |
Set trace prompt to print seconds.nanoseconds | PS4='+ $(date "+%s.%N")\011 ' |
Find all instances of first column with unique rest of line, and output a count for each first column that found in unique lines. | sort file | uniq | cut -f1 -d' ' | uniq -c | rev |
Renumbers all windows in the session in sequential order. | tmux movew -r |
Search the current directory tree for regular files omitting directory `omit-directory' | find . -name omit-directory -prune -o -type f -print |
Find '.git' directories in directory tree /path/to/files and print the pathnames of their parents | find /path/to/files -type d -name '.git' -exec dirname {} + |
Forward all connections to client localhost 3307 via the SSH tunnel to gateway and then connect to host 1.2.3.4 to port 3306 | ssh -f user@gateway -L 3307:1.2.3.4:3306 -N |
Calculate a list of duplicate md5 sum hashes for all the ".java" files in the current directory | md5sum *.java | awk '{print $1}' | sort | uniq -d |
Find all files/directories under current directory with 'FooBar' in their paths and copy them to ~/foo/bar | find . | grep FooBar | xargs -I{} cp {} ~/foo/bar |
Find all files/directories whose names start with 'readme' (case insensitive) under '/usr/share/doc' directory tree | find /usr/share/doc -iname readme\* |
Move all lines starting with "Ca" to the beginning of the file | nl -n rz ca | awk -vOFS="\t" '/Ca/{$1="#"$2} {$1=$1}1' | sort -k1,1 | cut -f2- |
Find all files under /somefolder matching the case insensitive regex '\(.*error.*\)\|\(^second.*\log$\)\|\(.*FFPC\.log$\)' in their paths | find /somefolder -type f | grep -i '\(.*error.*\)\|\(^second.*\log$\)\|\(.*FFPC\.log$\)' |
Create a table from '111 22 3\n4 555 66\n' with columns separated by a single space | echo -en '111 22 3\n4 555 66\n' | column -t | sed 's/ \([0-9]\)/\1/g' |
Print which files differ in "PATH1/" and "PATH2/" recursively excluding any files that match any pattern in "file1" | diff PATH1/ PATH2/ -rq -X file1 |
Print the average time of 4 ping requests to "www.stackoverflow.com" | ping -c 4 www.stackoverflow.com | sed '$!d;s|.*/\/.*|\1|' |
Report file system disk space usage in human readable format | df -h |
Split "input.txt" into files of at most 10 bytes each with prefix "/tmp/split-file" | split -b 10 input.txt /tmp/split-file |
Archive the entire file system into tarfile.tar.bz2 | find / -print0 | xargs -0 tar cjf tarfile.tar.bz2 |
Replace "inputfile" with a sorted unique list of its contents | sort inputfile | uniq | sort -o inputfile |
find all files having certain word in its name in the current folder | find . -name "*bsd*" -print |
Find all regular files in the current directory and its subdirectories. | find . -type f |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.