nl_command
stringlengths 14
387
| bash_code
stringlengths 0
532
|
---|---|
find all the java script files in a folder and display them in a sorted order based on their type and save the output to a file | cat `find src/js -type f -name "*.js" -print0 | xargs -0 stat -f "%z %N" | sort -n | sed -e "s|[0-9]*\ \ ||"` > public/js/myCleverScript.js |
Kill all instances of "dropbox" owned by the current user | killall -u "$" dropbox |
dispaly a long listig of all the files in the home folder which are bigger than 100KB and discard any errors | find /home -size +100000 -ls 2>/dev/null |
Removes empty folder 'edi' and 'edw'. | rmdir edi edw |
Split "domains.xml" into files of at most 50000 lines each with a numeric suffix of length 4 and prefix of "domains_" | split -a 4 -d -l 50000 domains.xml domains_ |
find directories that have been modified in the last seven days | find . -mtime -7 -type d |
Print the kernel configuration options found in "/proc/config.gz" | cat /proc/config.gz | gunzip |
Read a line from standard input with prompt "Enter your choice: " and save response to variable "choice" | read -p "Enter your choice: " choice |
Print all distinct characters in input "He likes cats, really?" | echo "He likes cats, really?" | fold -w1 | sort -u |
searches through the root filesystem for the file named Chapter1. | find / -name Chapter1 -type f |
Unzip and extract "*\ [^ =][^ =]*=.*" from "input.gz" | zcat input.gz | sed -n 's/.*\ [^ =][^ =]*=.*/\1/p' |
Search for the regex "\$wp_version =" in all the regular files that end with '/wp-includes/version.php' in their paths in directories/files taken from the glob pattern '/home/*//public_html/' and show the matched lines along with the file names | find /home/*/public_html/ -type f -iwholename "*/wp-includes/version.php" -exec grep -H "\$wp_version =" {} \; |
Print the date followed by the host name | echo `date` `hostname` |
Remove "\r" at the end of each line in "infile" and display the result as printable characters or backslash escapes | cat infile | sed 's/\r$//' | od -c |
Remove trailing white spaces from all files under current directory ignoring .git, .svn directories and binary files | find . -not \ -type f -print0 | xargs -0 file -In | grep -v binary | cut -d ":" -f1 | xargs -0 sed -i '' -E "s/[[:space:]]*$//" |
display all regular/normal files in temp folder and display the filename along with file size | find tmp -type f -printf "f %s %p\n" |
find all the php/javascript files in current folder using regular expressions | find . -regex '.+\.\' |
Sort lines in "set1" and "set2" to standard output preserving only unique lines | sort -u set1 set2 |
Create a symbolic link named "/lib/libc.so.0" to "/lib/libc.so.6" | ln -s /lib/libc.so.6 /lib/libc.so.0 |
Search for directory foo ignoring case | find . -iname foo -type d |
Count the number of files named 'job.history' under '/data/SpoolIn' directory tree that match 'FAIL' in their contents | find /data/SpoolIn -name job.history | xargs grep -l FAIL | wc -l |
List all files/directories under /myfiles directory | find /myfiles -exec ls -l {} ; |
search in the entire file system for the files firefox, thunderbird, seamonkey and display all the files expect those having the words "10_Recommended" or "repo" | sudo find / -type f 2>/dev/null|grep -v '' |
Find all files in the `sourceDir' directory tree | find sourceDir -mindepth 1 |
Find all regular files matching the name pattern '*.?htm*' under '/srv/www' and '/var/html' directory tree | find /srv/www /var/html -name "*.?htm*" -type f |
Counts lines in file fileName ignoring empty lines and lines with spaces only. | awk '!/^[[:space:]]*$/{++x} END{print x}' filename |
Find files whose pathnames end in "f" | find . -path '*f' |
Merge the first "$lc" lines of "current.txt" and the last "$lc" lines of "current.txt" and display the result as a comma separated table | paste <(head -"$lc" current.txt) <(tail -"$lc" current.txt) | column -t -o, |
List the directory contents of the current working directory | echo $(ls $(pwd)) |
Find all files under $YOUR_DIR | find $YOUR_DIR -type f |
display all the files in the current folder which have been modified in the last 2 days | find . -mtime -2 |
Find *.jpg screenshots that are bigger than 500k | find ~/Images/Screenshots -size +500k -iname '*.jpg' |
Find all files called wp-config.php in the /var/www directory and below | find /var/www/ -name wp-config.php |
find all the text files in the folder /home/calvin and do not search beyond 2 levels | find /home/calvin/ -maxdepth 2 -name “*.txt” |
Filter the cron list of user "user" through "my_wonderful_sed_script" and re-apply the resulting output. | crontab -u user -l | sed "$my_wonderful_sed_script" | crontab -u user - |
Find files on the system created during the last 50 days | find / -ctime -50 |
Print unique lines in sorted file "a.txt" compared to sorted file "b.txt" | comm -23 a.txt b.txt |
List all regular files in the current directory tree that were modified less than 60 minutes ago | find . -mmin -60 -type f -exec ls -l {} + |
Find all symlinks in the /myfiles directory tree | find /myfiles -type l |
find all the files in the current directory and sub-directories, that were edited within the last 1 hour and execute the list command with long listing format | find -mmin -60 -exec ls -l {} \; |
find all the directories in the current folder that are empty | find -type d -empty |
generates a list of all files beneath the current directory whose filename DOES NOT end in .html, so it matches files like *.txt, *.jpg, and so on. | find . -type f -not -name "*.html" |
Exits from script with exit code 1. | exit 1 |
kill all background jobs | jobs -p | xargs kill |
Print a space separated list of numbers from 1 to 10 with no trailing new line | seq 10 | xargs echo -n |
Delete all files throughout the entire filesystem that are no longer owned by a valid user. | find / -nouser | xargs -0 rm |
Kill all processes matching the string "myProcessName" | ps -ef | grep myProcessName | grep -v grep | awk '{print $2}' | xargs kill -9 |
Find all *company* files/directories under /basedir with null character as the delimiter | find /basedir/ -iname '*company*' -print0 |
Find all files/directories that are bigger than 100 bytes under '/home/apache' directory tree | find /home/apache -size 100c -print |
Extract data from HTML table in "mycode.html" | paste -d: < < |
Check md5sum of directory /path against the checksum saved in file 'file' | du -csxb /path | md5sum -c file |
find all the files in the folder "/usr/app/etl/01/OTH/log/tra" which have been modified in the last 240 hours excluding hidden files and those with the name "/usr/app/etl/01/CLE/par/files_to_skip.par" | find /usr/app/etl/01/OTH/log/tra -type f ! -name ".*" -mtime -10 | egrep -vf /usr/app/etl/01/CLE/par/files_to_skip.par |
Find all files in the current directory tree whose path names match pattern './sr*sc' | find . -path './sr*sc' |
Move all files and directories not starting with "l" in "/mnt/usbdisk" to "/home/user/stuff/." | mv /mnt/usbdisk/[^l]* /home/user/stuff/. |
get the git user access | su git |
print all filenames of files under current dir containing 'foo', case-insensitive | find . -type f -exec grep -il 'foo' {} \; |
Find all files/directories named 'top' in the entire filesystem | find / -iname top |
Check if "server1" and "server2" have the same list of RPMs installed | diff < < |
Change to parent directory and resolve any symlinks in the resulting path, making the physical path the current one. | cd -P .. |
Finds the folder where temporary files would be written to, and save path to it in a 'TMPDIR' variable. | TMPDIR=`dirname $(mktemp -u -t tmp.XXXXXXXXXX)` |
Print second section of line <line> where sections are separated by one or more whitespace. | echo -e "<line>" | sed 's:\s\+:\t:g' | cut -f2 |
Execute "ls" every 2 seconds | watch ls |
Find all strings matching pattern "^${KEY}${DELIMITER}" in $FILE file and print rest of string after $DELIMITER | cat "$FILE" | grep "^${KEY}${DELIMITER}" | cut -f2- -d"$DELIMITER" |
Gets back to the foreground a job with number 2. | fg 2 |
List all IP addresses assigned to current hostname, pausing for user interaction after each page. | more /etc/hosts | grep '[[:space:]]*'`hostname`'[[:space:]]*' | awk '{print $1}' |
Changes group ownership of 'shared' to 'Workers'. | chgrp Workers shared |
display all normal/regular files in a folder | find /home/the_peasant -type f |
find all the javascript files in current folder using regular expressions | find . -regex '.+\.js' |
Print all files that exceed 1000 blocks and were modified at least a month ago | find / -size +1000 -mtime +30 -exec ls -l {} \; |
Archive "src" to "dest" via ssh with permissions set to 755 | rsync -avz --chmod=ug=rwx --chmod=o=rx -e ssh src dest |
Print A record for domain 'domain.' from 'ns1.newnameserver' nameserver | dig @ns1.newnameserver domain. a |
display all the files in the current folder excluding those that are present in the path "./etc" | find . ! -wholename "./etc*" |
List all files/directories under /data1/Marcel with their file information which are greater than 524288 bytes and were modified or accessed more than 1 year ago | find /data1/Marcel -size +1024 \ -ls -exec file {} \; |
Count number of users logged in | who | awk -F' ' '{print $1}' | sort -u | wc -l |
find all the files in the home folder which are less than 42 Bytes | find / -size 42 |
find all the files in the file system which have been accessed in the last 1 day | find / -atime -1 |
Find all files/directories named 'fprintf.c' under '/usr/src' directory tree | find /usr/src -name fprintf.c |
Find all Subscription.java files/directories under current directory and enter into the parent directory of the first one found | cd $ |
Print common lines of files "file1", "file2", "file3", and "file4" | comm -12 <(comm -12 <(comm -12 < <) <) < |
Count the number of regular files in directory tree ${DIRECTORY} that contain a vowel in their names | find ${DIRECTORY} -type f -print | sed -e 's@^.*/@@' | grep '[aeiouyAEIOUY]' | wc -l |
Execute script /tmp/echoargs on all files from the /tmp/foo directory tree | find /tmp/foo -exec /tmp/echoargs {} \; |
search for all the files in the current folder which start with gen and end with bt2 and assign the output list to the variable var. | var="$(find . -name 'gen*.bt2')" |
Removes all top-level *.pdf files in a current folder. | rm -f *.pdf |
Search the files from the current directory tree for "foo" | find . -exec grep -l foo {} + |
Prints information about active network interfaces in system. | echo "$" |
this will recursively grep all the files, compressed or uncompressed.2 If you want to grep only the compressed files then find + zgrep would be a better option. | find /path/to/dir -name '*.gz' -exec zgrep -- 'pattern' {} + |
Find all regular files that reside in the current directory tree and were last modified more than 4 days ago | find . -type f -mtime +4 |
Get current directory name without full path, ie. the part after the last / | pwd | awk -F / '{print $NF}' |
Find all files/directories with '.pdf' extension excluding 'pdfs' directory and all of its contents | find . -name "*.pdf" -print | grep -v "^\./pdfs/" |
search for the regular/normal file 'myfile' in the folder /root excluding those that are present in the /root/work directory | find /root/ -path '/root/work' -prune -o -name myfile -type f -print |
Delete all directories under '.cache/chromium/Default/Cache' directory tree that are at least 1 level deep and are bigger than 100 MB in size | find .cache/chromium/Default/Cache/ -mindepth 1 -type d -size +100M -delete |
Force delete all the regular/normal files in the current folder and do not search in the sub folders | find . -maxdepth 1 -type f -exec rm -f {} \; |
Find all files that are set group ID to 10 | find . -group 10 -perm -2000 -print |
Print 7 spaces in a row | yes ' ' | head -7 | tr -d '\n' |
Copy all files matching "*.sh" in "$from/*" to "root@$host:/home/tmp/" compressing data during transmission | rsync -zvr --include="*.sh" --exclude="*" $from/* root@$host:/home/tmp/ |
Compute the mean average of the word count of *.txt files in the home directory | find ~/ -name '*.txt' -print0 | xargs -0 wc -w | awk 'END { print $1/ }' |
Find all directories under current directory and change their permission to 644 | find -type d -print0|xargs -0 chmod 644 |
Read the history file and append the contents to the history list | history -r |
Find all regular files under current directory tree, prepend '#' at the beginning of the lines that contain 'abc' in those files and modify them in-place | find . -type f -exec sed -i ‘s/.*abc.*/#&/’ {} \; |
Find files in the current directory tree whose permissions are 775 | find . -perm 775 |
Subsets and Splits