nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all files under /path and below writable by `group' and `other'
find /path -perm -g+w,o+w
Finds files in 'directory' folder with the same name and location but different content than files in 'directory.original' folder and saves location of such files to 'directories' variable.
directories=$
Lists content of all subfolder (without recursion) in a current folder.
ls -d -1 $PWD/**/*
Read a line from standard input into variable "message" with the prompt "Please Enter a Message: $cr"
read -p "Please Enter a Message: $cr" message
split processed content of the file inout_file into pieces per 2000000 named as "out-prefix-NNN"
sed 's/\\/\1\n\2/' input_file | split -l 2000000 - out-prefix-
search for the ip "192.168.1.5" in all the files in /etc folder
find /etc/ -iname "*" | xargs grep '192.168.1.5'
Get A record for domain $domain
dig -t A $domain
Change directory to the "lib" directory located two parent directories above the path to command "perl"
cd $(dirname $(dirname $(which perl)))/lib
Recursively prints .txt files in current directory
find $ -name \*.txt -print
Search directory tree $DIR for *.txt files
find $DIR -name "*.txt"
List environment variables whose name contains "X"
set | grep -oP '^\w*' | grep X
display all the header files and cpp files in the current folder
find \ -print
List each unique character in "file" prefixed by number of occurrences
grep -o . file | sort | uniq -c
search for files which are writable by either their owner or their group
find . -perm /220
List all *fink* files/directories in entire file system
find / \( -type f -or -type d \) -name \*fink\* -ls
display all the statistics of the files in the current folder and discard the errors
find . -type f -exec stat {} \; > /dev/null
Recursively copy all directories in "/path/to/source" to "/path/to/dest/" preserving directory hierarchy
find /path/to/source -type d | cpio -pd /path/to/dest/
search for a word in all the php files in the current folder and display the matching lines. PLus at the end takes multilple files as input
find . -name \*.php -type f -exec grep -Hn '$test' {} \+
search for text files in the folders /home/hobbes/ /home/calvin/
find /home/hobbes/ /home/calvin/ -name “*.txt”
change the permissions of all the files ending with "fits" in the folder "/store/01"
find /store/01 -name "*.fits" -exec chmod -x+r {} \; \
Add "A new line" on top of each *.py files under current directory
perl -pi -e 'BEGIN { print "A new line" }' $
Print position number of day '9' in fourth line of calendar output for September, 2009.
cal 09 2009 | awk 'BEGIN{day="9"}; NR==4 {col=index($0,day); print col }'
create directory /var/svn as user root
sudo mkdir /var/svn
Copy all files in current directory that do not match */exlude-path/* in their paths to /destination/ preserving directory structure
find . -type f -not -path '*/exlude-path/*' -exec cp --parents '{}' '/destination/' \;
Delete all .svn files/directories under current directory
find . -name .svn | xargs rm -fr
search for files having python in filename
find / -iname '*python*'
Find files with size more than 200557600B and which are more than 2 days old under ${userdir}/${i}/incoming directory
find ${userdir}/${i}/incoming -mtime +2 -type f -size +200557600c -ls
find all regular/normal files in current folder and display the filename and size
find $/* -type f -exec stat -c "f%15s %n" {} +
Find all files under current directory whose file type description contains "image", display only path to each file.
find . -type f -exec file {} \; | grep -o -P '^.+: \w+ image'
perform a case insensitive search
find / -type d -iname "apt" -ls
search for dbmsspool.sql file in the current folder
find . -print|grep ?i dbmspool.sql
Find all regular files under current directory
find . -type f
Print "yes" 4 times followed by 1 "no"
yes yes | sed -e 5s/yes/no/ -e 5q
Search the /path directory tree for files lacking the group writable bit
find /path ! -perm /g+w
Set permissions to 600 for regular files under media/
find media/ -type f -exec chmod 600 {} \;
Find recursively all Emacs backup files in the current directory and remove them
find . -name '*~' | xargs rm
display all symbolic links in the folder "myfiles"
find /myfiles -type l
Make "bar" executable
chmod +x bar
Find all Executable files
find / -perm /a=x
Creates temporary file and saves path to it in 'content_dir2' variable.
content_dir2=$(mktemp)
find all jar files in current folder and search for a file in all these jar's
find . -name "*.jar" -exec jar -tf {} \;|grep "message_track.properties"
Print the UID of the owner, GID of the group, the permission bits and the path into /tmp/dir1.txt for all files/directories under /path/to/dir1
find /path/to/dir1 -printf "%U %G %m %p\n" > /tmp/dir1.txt
Hunting down files with at least one banana
find . -type f -print0| xargs -0 grep -c banana| grep -v ":0$"
display a long listing of all the regular/normal files in the current folder along with their md5sum
find . -type f -exec sh -c 'printf "%s %s \n" "$" "$"' '' '{}' '{}' \; | awk '{$8=""; print $0}'
search for al cpp files in current folder and replace all expect the parent directory name of these files and display it them sorted order
find . -name '*.cpp' | sed -e 's/\/[^/]*$//' | sort | uniq
Find and display contents of somefile.cf in a Weblogic domain directory
find $ 2> /dev/null -exec ls {} \; -exec cat {} \;
Save the list of all regular files accessed less than 10 days ago as `March.files'
find / -type f -atime -10 > March.files
Find files which are more than 2 days old under ${userdir}/${i}/incoming directory and remove them
find ${userdir}/${i}/incoming -mtime +2 -type f -exec rm {} \;
Find all regular files in the current directory tree last modified between 1 and 3 days ago and list them using format '%Tc %p\n'
find ./ -daystart -mtime -3 -type f ! -mtime -1 -printf '%Tc %p\n'
Find files whose pathnames contain "string" and print these pathnames replacing 'search string' with 'new string'
find . |xargs grep search string | sed 's/search string/new string/g'
Replace the first occurrence of "foo" with "bar" on every line in .txt files from the current directory tree
find . -type f -name '*.txt' | xargs --replace=FILE sed --in-place 's/foo/baz/' FILE
Set the group to "username" for all files with GID=1000 in the current directory tree
find -gid 1000 -exec chown -h :username {} \;
Find all files whose filename does not end with *.html.
find . -type f -not -name "*.html"
List environment variables whose name matches '^\w*X\w*'
set | grep -oP '^\w*X\w*(?==)'
Create a symbolc link in the current directory to "target"
ln -s target
Wrap each line in "longline" to a maximum of 30 characters breaking at spaces
fold -w30 -s longline
Non-recursively finds all '*.pdf' files in a current folder and removes them.
find . -maxdepth 1 -name "*.pdf" -print0 | xargs -0 rm
Find all *.txt and *.json files
find . -type f \
Sort and remove duplicate lines in the output of "finger"
finger | sort -u
search for "message.txt" in the folder .cache/bower and display its contents
find .cache/bower/ -name "message.txt" | xargs cat
Find links to any file that happens to be named `foo.txt'
find . -lname \*foo.txt
Print common files of directory "one" and "two"
comm -12 <(ls one) <(ls two)
Find disk usage of all files inside the directory
du -a
Find all files on the system whose names are 'autoload.php'
find / -name autoload.php
Calculate the md5 sum of hex byte 61
echo -n -e '\x61' | md5sum
display all the files in the current folder excluding those which are present in "./src/emacs" folder
find . -path './src/emacs' -prune -o -print
Replace 'company' with 'newcompany' in all files under current directory and keep backups with .bakup extension
find -type f -print0 | xargs -0 sed -i .bakup 's/company/newcompany/g'
Find all files under and below the current working directory with the word California in the file, and count the number of lines in the output
find . -type f -exec grep California {} \; -print | wc -l
Finds strings with dot-separated sequence of numbers, and prints part of that sequence before the second and third dot.
echo "$f" | grep -Eo '[0-9]+[.]+[0-9]+[.]?[0-9]?' | cut -d. -f3
Print current date as epoch seconds
date +%s
Prints latest modified file in a directory
ls -1t | head -1
Create a compressed archive from "www" and split the contents into files of at most 1073741824 bytes and use prefix "www-backup.tar."
tar czf - www|split -b 1073741824 - www-backup.tar.
search for a word in all the .C files in the current directory
find . -name "*.c" -exec grep -ir "keyword" {} ";"
Find all hidden files starting from the directory given as variable $FOLDER
find $FOLDER -name ".*"
Find all regular files under current directory (no subdirectories) and replace every occurrences of 'toreplace' with 'replace' in those files
find . -maxdepth 1 -type f -print0 | xargs -0 sed -i 's/toreplace/replaced/g'
find all the files that have been modified in the last 2 days
find . -type f -daystart -mtime -2
Prepend time stamps to entries in "/path/to/log" as they appear and write to "/path/to/log-with-timestamps"
tail -f /path/to/log | perl -pne 'print scalar(localtime), " ";' > /path/to/log-with-timestamps
display a long listing of all regular files in current folder which have been modified in the last 60 minutes
find . -mmin -60 -type f -ls
Removes all empty folders under current folder.
find . -type d -exec rmdir {}\;
search for all html files in current folder folder and create a zip file of all these files
find . -type f -name "*.html" | zip -j all-html-files -@
Archive "src/bar" on host "foo" to local directory "/data/tmp"
rsync -avz foo:src/bar /data/tmp
Save the short host name appended with ".mysqldb" in variable "DBPREFIX"
DBPREFIX="$.mysqldb"
Search directory tree /srv/${x} for regular files accessed at least 10080 minutes ago, and remove those files
find /srv/${x} -mindepth 1 -type f -not -amin -10080 -exec rm {} \;
Find symbolic links under /etc/
find /etc -type l
Display file status for all regular files in the current directory tree suppressing error messages
find . -type f -exec stat {} \; > /dev/null
find all the files in the current directory which start with t and have been modified between one hour and 12 hours ago.
find . -mmin -720 -mmin +60 -type f -name "t*" -exec ls -l '{}' \;
search for a word in all the normal/regular files in the current folder
find . -type f | xargs grep "text"
Find all files/directories named 'foo.bar' under './dir1' and './dir2' directory trees
find ./dir1 ./dir2 -name foo.bar -print
Find all 777 permission files/directories under current directory tree
find -perm 777
Find files that end in ".gz" and execute "awk -F, '$1 ~ /F$/'" on their unzipped contents
find . -maxdepth 1 -name \*.gz -print0 | xargs -0 zcat | awk -F, '$1 ~ /F$/'
show all the regular files in current folder
find . -type f -print0
Replace "foo" with "bar" in all PHP files in the current directory tree
find . -name "*.php" -exec sed -i 's/foo/bar/g' {} \;
find all the database files in the folder /var/named
find /var/named -type f -name *.db
Search for the regex $greppattern in all files with '.c' or '.h' extension under $searchpath with name pattern $filepat and show the matched line numbers, file names and matched lines
find "$searchpath" -name "$filepat.[ch]" -exec grep --color -aHn "$greppattern" {} \;
Display differences between /tmp/test1 and /tmp/test2.
diff /tmp/test1 /tmp/test2
Find all *.txt files/directories under current directory and execute the python script myscript.py with all their paths as arguments to the script
find . -name "*.txt" -exec python myscript.py {} +
display all the files in the current folder which have been modified in the last 24 hours
find . -mtime -1
Change onwer to "root" and group to "wheel" of "com.xxxx.adbind.plist"
sudo chown root:wheel com.xxxx.adbind.plist
Find all directories matching pattern "*log*" in the current directory tree and print the last 2 lines of their 'ls' listing
find . -type d -name "*log*" | xargs -I {} sh -c "echo {};ls -la {} | tail -2"
Find all directories in the current directory tree that were last modified more than 5 minutes ago but less than 60 minutes ago
find . -mmin -60 -mmin +5