nl_command
stringlengths 14
387
| bash_code
stringlengths 0
532
|
---|---|
Count the number of all directories under current directory non-recursively | find . -mindepth 1 -maxdepth 1 -type d | wc -l |
Print epoch seconds for given time string "Oct 21 1973" | date -d "Oct 21 1973" +%s |
Find all files with '.conf' extension under '/etc' directory tree that have been modified in the last 30 minutes | find /etc -name "*.conf" -mmin -30 |
Print 'Since -printf is an action the implicit -print is not applied\n' for every file named 'file' found under current directory tree | find -name file -printf 'Since -printf is an action the implicit -print is not applied\n' |
Unsets random one from first five array members. | unset array[`shuf -i 0-4 -n1`]; |
Replace all spaces with comma in ${TO_IGNORE[@]}, append with '--ignore ' and save the resultant string to variable 'ARGS' | ARGS="--ignore `echo ${TO_IGNORE[@]} | tr ' ' ','`" |
Find all directories under current directory and set their permission to 755 | find -type d exec chmod 755 {} + |
List files larger than 9MB residing in the current directory and below | find . -size +9M |
find dirctory files which modification time is 7 days ago | find . -mtime -7 -type d |
Counts number of occurences of all ip addresses in 'ip_addresses' file, and prints all addresses with number of occurences in a descending order. | cat ip_addresses | sort | uniq -c | sort -nr | awk '{print $2 " " $1}' |
search for a word in all the php files in the current folder and display the count of all matching lines. | find . -name \*.php -type f -print0 | xargs -0 -grep -Hn '$test' | wc -l |
Remove all files named `junk' and `dummy' | find . \ -exec rm '{}' \; |
display the name of all directories in the current folder and do not search in sub directories | find . -type d -maxdepth 1 -exec basename {} \; |
display all files in the current folder while discarding the errors save the output to a file | find . 2>/dev/null >files_and_folders |
search for files in a directory and check the validity of a command by giving the file as input | find … -print0 | xargs -0 -n1 invalid_command |
Copy file in current directory of local host to host "remote", connecting as ssh user matching current local username, and copying the file in home directory on remote host - enable compression during transfer. | scp -C file remote: |
search for the regulars file starting with HSTD which have been modified yesterday from day start and copy them to /path/tonew/dir | find . -type f -iname ‘HSTD*’ -daystart -mtime 1 -exec cp {} /path/to new/dir/ \; |
Archive current directory to "/some/path" on localhost, using ssh to authentify as user "me", only update files that are newer in the source directory. | rsync -auve "ssh -p 2222" . me@localhost:/some/path |
search for all the foo.txt files in the current folder and move them to another location | find . -name foo.txt -print0 | xargs -0 -I{} mv {} /some/new/location/{} |
Change permissions of all regular files in the ~/dir_data directory tree in accordance with mode `a-x,u+w' | find ~/dir_data -type f -exec chmod a-x,u+w {} \; |
Print common lines in sorted files "ignore.txt" and "input.txt" | comm -12 ignore.txt input.txt |
Find all 15MB files | find / -size 15M |
find all the empty directories in the current folder | find . -type d -empty |
Find all files/directories under '/etc' directory tree that have been modified after '/etc/motd' | find /etc -newer /etc/motd |
Archive "src" to "dst" updating files existing in "dst" | rsync -a -v src dst |
Print summary of new/missing files, and which files differ between dir_one and dir_two, sorted alphabetically. | diff -qr dir_one dir_two | sort |
Limit each line in "your_file" to 80 characters and view via "more" | fold -80 your_file | more |
Print absolute path of java executable | readlink -f $ |
Print every 3 characters of standard input as a line | fold -w3 |
Find all *.gz files/directories under asia and emea directory | find asia emea -name \*.gz |
search all the ".sh" files in the /usr folder and follow the symbolic links to their original file | find /usr -follow -name '*.sh' |
Retrieve column number from column name "Target" in file "table" | head -1 table | tr -s ' ' '\n' | nl -nln | grep "Target" | cut -f1 |
Search the *.txt files from the current directory tree for "string" | find . -name "*.txt" -print0 | xargs -0 egrep 'string' |
List all files in the current directory tree including those that may contain spaces in their names | find . -print0 | xargs -0 -l -i echo "{}"; |
Compares two listings 'ls' and 'ls *Music*', showing only strings that unique for first listing. | comm -23 < < |
Find all files under $d directory and set read-write permission for owner and group and no permission for other for those files | find $d -type f -exec chmod ug=rw,o= '{}' \; |
Gets string with MAC addess of network interface eth0. | ifconfig eth0 | grep HWaddr |
Find how many files are in a path | find . -type f -exec basename {} \; | wc -l |
Find all files in your home directory and below that are smaller than 100M. | find ~ -size -100M |
Get the path of running Apache | ps -ef | grep apache |
Find all files under current directory whose file type description contains "image", display only path to each file. | find . -type f -exec file {} \; | awk -F: '{if ($2 ~/image/) print $1}' |
Find SGID files | find / -perm +2000 |
Find regular files under / that contain "string" and clear out their contents | find / -maxdepth 1 -xdev -type f|xargs grep -l 'string'| xargs perl -pi -e 's/.//g' |
Change all files in "~" which are owned by the group "vboxusers" to be owned by the user group "kent" | find ~ -group vboxusers -exec chown kent:kent {} \; |
Sort the contents of file "ips.txt", eliminate duplicate entries, and prefix each entry with number of occurrences. | sort ips.txt | uniq -c |
display all the files in the folders mydir1, mydir2 which are bigger than 2KB and have not been accessed in the last 30*24 hours | find /mydir1 /mydir2 -size +2000 -atime +30 -print |
Move all files excluding hidden files in "/path/subfolder/" to "/path/" | mv /path/subfolder/* /path/ |
Removes 5 oldest files in the current folder. | ls -t *.log | tail -$tailCount | xargs rm -f |
Save full path of command "tr" to variable "TR" | TR=`which tr` |
Prints file descriptor of executed built-in 'true'. | echo < |
Find all regular files under '/directory_path' directory tree that have been modified within the last day | find /directory_path -type f -mtime -1 -print |
Archive "/source" and all files under "folder/" to "/dstfolder/" on host "remoteserver" as user "user" without copying files that already exist | rsync -avz --ignore-existing /source folder/* user@remoteserver:/dstfolder/ |
Save absolute path of the script filename in variable "SCRIPT" | SCRIPT="$(readlink --canonicalize-existing "$0")" |
Find all files/directories under _CACHE_* directories | find _CACHE_* |
Search for files whose size is between 100 kilobytes and 500 kilobytes | find . -size +100k -a -size -500k |
Search all regular files in the current directory tree for "string" | find . -type f | xargs -d '\n' grep string |
Search for files which are writable by somebody | find . -perm /222 |
display all the header files and cpp files in the current folder | find . -regex '.*\.\' |
Copy '/path/to/source' from remote "username@computer" to local "/path/to/dest" | rsync -r username@computer:/path/to/source /path/to/dest |
Recursively change owner to "amzadm" and group to "root" of all files in "/usr/lib/python2.6/site-packages/awscli/" | chown amzadm.root -R /usr/lib/python2.6/site-packages/awscli/ |
Remove any file containing string "GUI" | find / -type f -print0 | xargs -0 grep -liwZ GUI | xargs -0 rm -f |
From a script, output the name of the script itself, without containing directories - from a shell, output the name of the shell. | basename -- $0 |
Search all *.c files from the current directory tree for "hogehoge" | find . -name \*.c -print0 | xargs -0 grep hogehoge /dev/null |
display all the regular/normal files in current folder | find . -type f -print0 |
Find all the .c files in the current directory tree that contain the string ‘stdlib.h’ | find . -name '*.c' | xargs grep 'stdlib.h' |
Output a CSV file as a formatted table | sed 's/^,/ ,/' test2.csv | tr -d \" | column -s, -t |
set alisa "12np" for command 'ssh mydomain\\stephencheng@[email protected]' | alias 12np='ssh mydomain\\stephencheng@[email protected]' |
Search for 'specific string' in all files matching the name pattern '“*.[txt|TXT]”' under current directory tree | find . -name “*.[txt|TXT]” -print | xargs grep “specific string” |
Find all directories recursively starting from / and count them | find / -type d | wc -l |
Save the list of directories modified a fortnight ago to `deploy.txt' removing the leading ./ from the file names | find . -type d -mtime 14 | sed -e 's,^\./,,' > deploy.txt |
replace a word in all the regular/normal files in the current folder | find . -type f -print0 | xargs -0 sed -i 's/Application/whatever/g' |
Find all regular files with space in their names under current directory and rename them by replacing all spaces with _ | find -name "* *" -type f | rename 's/ /_/g' |
List all regular files in and below the home directory that were modified more than 5 years ago | find ~ -type f -mtime +1825 |xargs ls -l |
List all directories and subdirectories | find . -type d |
Read a single character from standard input into variable "runCommand" with the prompt "Pick a letter to run a command [A, B, or C for more info] " | read -n1 -p "Pick a letter to run a command [A, B, or C for more info] " runCommand |
Create symbolic links in the current directory for all files under "bar1" that are not directories and do not end in ".cc" | find bar1 -name '*foo*' -not -type d -not -name '*.cc' -exec ln -s $PWD/'{}' bar2/ \; |
Delete all files in the current directory tree whose names end with ~ | find . -name "*~" -delete |
find all the ".mov" video files in the current folder and convert them to flv using ffmpeg. print0 is used to handle files with newline in their names | find . -iname "*.mov" -print0 | xargs -0 -i sh -c 'ffmpeg -i {} -f flv `basename {}`' |
Find files/directories writable by group and others under the /path directory | find /path -perm -022 |
Find all files with '.conf' extension under '/etc' directory going into at most 2 level deep and show the last 10 of them | find /etc -maxdepth 2 -name "*.conf" | tail |
Find all JPG files under the "$SOURCE" directory and below | find "$SOURCE" -type f -iname '*.jpg' |
search for the file ".user.log" in a folder | find /nfs/office -name .user.log -print |
Find all php files in a directory | find . -type f -name "*.php" |
Move the directory named "some-dir" and residing under the current one to x/ | find ./ -maxdepth 1 -name "some-dir" -type d -print0 | xargs -0r mv -t x/ |
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 under current directory with their sizes and paths | find . -type f -printf '%s %p\n' |
Interpret /etc/bashrc in the current shell, ignoring lines that contain "mesg". | source <(grep -v "mesg" /etc/bashrc) |
delete all the ".bak" or swap files in kat folder | find kat -type f \ -delete |
See the word count of every *.txt file in the home directory | find ~/ -name '*.txt' -print0 | xargs -0 wc -w |
force delete all the directories the folder "test folder" | find 'Test Folder' -type d -print0 | xargs -0 rm -rf |
Change permssions of *.cgi files under directories htdocs and cgi-bin to 755 | find htdocs cgi-bin -name "*.cgi" -type f -exec chmod 755 {} \; |
Prints the day of last Friday in a current month. | cal | awk '$6{date=$6}END{print date}' |
Find the 5 largest regular files in the Downloads folder of tecmint's home directory. | find /home/tecmint/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5 |
search for text files in the folder /home/you which have been modified in the last 60*24 hours and display their contents | find /home/you -iname "*.txt" -mtime -60 -exec cat {} \; |
Gets IP address of 'eth0' network interface. | ifconfig eth0 | grep inet | cut -d: -f2 | cut -d' ' -f1 |
find all the regular/normal files in the folder /travelphotos which are bigger than 200KB and which do not have the word "2015" in their name | find /travelphotos -type f -size +200k -not -iname "*2015*" |
Find all regular files that reside in the current directory tree and were last modified more than 7 days ago | find . -type f -mtime +7 |
Find all files/directories under current directory tree whose paths match the pattern '*ACK*1' (case insensitive) | find . -iwholename "*ACK*1" |
Calculate the number of bytes of all the files listed in "files.txt" | <files.txt xargs stat -c %s | paste -sd+ - | bc |
Prints hierarchical process tree. | pstree |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.