nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Run "myprogram" in the current directory, pausing for user input at each page.
./myprogram | more
find all the files that have been modified exactly yesterday
find . -type f -daystart -mtime 1
For each line which has a common first field in file1.csv and file2.txt, output the first 4 fields of file1.csv
join -o 1.1,1.2,1.3,1.4 -t, <(sort file1.csv) <(sort file2.txt)
Create a tar archive with all *.java files under the current directory
find . -type f -name "*.java" | xargs tar cvf myfile.tar
Erase user's cron jobs and add one cron job to run "script" every minute.
echo "* * * * * script" | crontab -
Search the current directory for files whose names start with my
find . -name 'my*'
find all the directories in the folder $LOGDIR which have been modified in the last 5 days and delete them.
find $LOGDIR -type d -mtime +5 -exec rm -f {} \;
Unzip all *.zip files under current directory
find . -name '*.zip' | xargs -n1 unzip
Limits the number of results from grep to 2 lines
grep -o '1.' yourfile | head -n2
display a long list of the files in the current folder which have the word fuddel in all the files in the current folder and then search for the word fiddel in the previously matched files
find -exec grep -q fuddel {} ";" -exec grep -q fiddel {} ";" -ls
Rename the *.so files in the current directory tree prepending their names with "lib"
find . -name "*.so" -printf "mv '%h/%f' '%h/lib%f'\n" | bash
Find recursively all regular files in the current directory skipping hidden files and directories matching pattern '.?*'
find -name '.?*' -prune -o \( -type f -print0 \)
Print all non-hidden files in the current directory and its subdirectories
find . -not -path '*/\.*'
Search the current directory and two levels below for file `teste.tex'
find ~/ -maxdepth 3 -name teste.tex
Print the line number of each matching "<phrase>" in "<filename>"
nl -b a "<filename>" | grep "<phrase>" | awk '{ print $1 }'
Print file system disk space usage of the current directory's file system
df .
List all files from the current directory tree that were modified less than 60 minutes ago, omitting "."
find . -mindepth 1 -mmin -60 | xargs -r ls -ld
find all files in current folder which are bigger than 270MB and less than 300MB
find . -size +270M -size -300M
Finds strings with 'TEXT' from *.log files and prints all but first field from any space-delimited string.
grep -e TEXT *.log | cut -d' ' --complement -s -f1
Copy directory hierarchy from "$sourceDir" to "$targetDir"
find "$sourceDir" -type d | sed -e "s?$sourceDir?$targetDir?" | xargs mkdir -p
Print newline, word and byte count for all .h, .c, .cpp, .php and .cc files under current directory tree and also show the total counts
wc `find . -name '*.[h|c|cpp|php|cc]'`
Unset RBENV_VERSION variable in tmux session 'sessname' environment.
tmux set-environment -t sessname -u RBENV_VERSION
Change the owner of all files in "/empty_dir/" to "root" using at most 10 files at a time
ls /empty_dir/ | xargs -L10 chown root
Remount "extX" filesystem "/dev/hdaX" on "/" without writing in "/etc/mtab"
mount -n -o remount -t extX /dev/hdaX /
Request IP address for each domain name received on the command input
dig +short -f - | uniq
Search the home directory for OGG and MP3 files
find $HOME -iname '*.ogg' -o -iname '*.mp3'
Identify CMS version/releases accross all your Drupal websites
find /var/www/vhosts/*/httpdocs/ -type f -iwholename "*/modules/system/system.info" -exec grep -H "version = \"" {} \;
find all the files in the folder .home/calvin which have been modified in th last 45 minutes
find /home/calvin/ -mmin -45
Lists all directories in the current folder.
ls -d ./*/
find all java files in current folder and trim extra spaces, tab spaces
find . -type f -name "*.java" -exec perl -p -i -e "s/[ \t]$//g" {} \;
find all the files that have the word "fstab" in their name in a folder
find /etc -name *fstab*
Find all directories under 'A' directory tree excluding paths containing the directory 'a'
find A -type d \( ! -wholename "A/a/*" \)
Remove all regular files under $DIR directory tree that were accessed more than 5 days ago
find "$DIR" -type f -atime +5 -exec rm {} \;
Find all *.java files under current directory and archive them to myfile.tar
find . -type f -name "*.java" | xargs tar rvf myfile.tar
Find all files with '.txt' extension under '/home/my_dir' dirctory tree and display the number of lines in these files
find /home/my_dir -name '*.txt' | xargs grep -c ^.*
Reverse the text in $input by taking each 4 characters as each units and save the result in variable 'output'
output=$
Find all pdf files in /path and search for "your pattern" in the converted text output and print the paths to the matching files
find /path -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your pattern"' \;
Rename all *.jpg files under current directory by appending parent directory name at the beginning of their names if the name doesn't already contain the parent directory name
find . -name '*.jpg' -execdir bash -c 'd="${PWD##*/}"; [[ "$1" != "$d-"* ]] && mv "$1" "./$d-$1"' - '{}' \;
Find all files whose name or type description includes "text", display only paths to files.
find . -exec file {} \; | grep text | cut -d: -f1
Search the current user's home directory and its sub-directories for any files accessed after alldata.tar was last accessed and add them to that same tar archive.
find ~/ -newer alldata.tar -exec tar uvf alldata.tar {} \;
Save the greater version number of "$1" and "$2" into variable "ver"
ver=`echo -ne "$1\n$2" |sort -Vr |head -n1`
Print 'Empty dir' if $some_dir is empty
if find /some/dir/ -maxdepth 0 -empty | read v; then echo "Empty dir"; fi
Write out the entire directory hierarchy from the current directory
find .
Add a number prefix followed by ')' to each line in "$string"
echo "$string" | nl -ba -s') '
Search the /path/to/dir directory tree for .c files
find /path/to/dir -name \*.c
Reverse the order of lines in "dax-weekly.csv" keeping the first line the same
cat dax-weekly.csv | awk '1 { last = NR; line[last] = $0; } END { print line[1]; for { print line[i]; } }'
display the file name and the file type of all the files in the current directory
find . -printf "%y %p\n"
Numerically sort file "files" by the second "-" separated value of each line ordered from least value to highest value
tac files | sort -t- -k2,2 -n
Perform syntax check on all PHP files in the current directory tree
find . -name \*.php -type f -print0 | xargs -0 -n1 php -l
Find directories in /home/vmail that match pathname "*/*/Maildir/.LearnAsSpam/new", and move them to folder .Junk/new
find /home/vmail/ -type d -path "*/*/Maildir/.LearnAsSpam/new" -exec sh -c '' ';'
Create master SSH control socket "my-ctrl-socket" in the background with no terminal or command execution with connection forwarding from localhost port 50000 to localhost port 3306 via "[email protected]"
ssh -M -S my-ctrl-socket -fnNT -L 50000:localhost:3306 [email protected]
Find all *.rb files/directories under current directory
find . -name *.rb
search for the file "file_name" in the folder /path
find /path -name file_name
list all files
find .
Print a count of each unique line in "ip_addresses"
sort ip_addresses | uniq -c
Search for files/directories which have read and write permission for their owner, and group and only read permission for others
find . -perm 664
Search recursively through /mydir, outputting only the base (leaf) name of each file, directory, symlink etc. without any containing directories, that is the part following the last slash.
find /mydir | xargs -I{} basename {}
Search for first match of the regex 're' in all *.coffee files under current directory and print the file names
find . -name \*.coffee -exec awk '/re/ {print FILENAME ":" $0;exit}' {} \;
Find all empty files under /tmp
find /tmp -type f -empty
display the list of all the text files present in the current directory excluding the search in certain paths.
find . -type f -name "*.txt" ! -path "./Movies/*" ! -path "./Downloads/*" ! -path "./Music/*" -ls
Print the names of any differing files in directories "dir1/" and "dir2/"
diff --brief --recursive dir1/ dir2/
Archive all directories in /path/to/directory/* (only command line arguments, no sub-directories) to files with .tar.gz extension transforming the full paths to relative paths
find /path/* -maxdepth 0 -type d -exec sudo tar -zcpvf {}.tar.gz {} \;
Calculate the md5 sum of the tar archive of "dir"
tar c dir | md5sum
Find files/directories named 'articles.jpg' under current directory tree and change their permission to 644
find . -name "articles.jpg" -exec chmod 644 {} \;
Print the list of the current directory's subdirectories
find . -type d -maxdepth 1
Counts lines in file $FILE.
count=$
Search "mygzfile.gz" for "string to be searched"
gunzip -c mygzfile.gz | grep "string to be searched"
Greps DNS zone transfer info on domain localdomain.com from NS @dc1.localdomain.com, finds strings with any-cased word 'Lawler' and strips last letter from each string.
VAR=`dig axfr @dc1.localdomain.com localdomain.com | grep -i Lawler | awk '{ getline ; $1=substr($1,1,length($1)-1); print $1 ; exit }'`
Find files/directories named blah under current directory
find ./ -name blah
Change permissions to 0755 for all directories in the /path directory tree
find /path -type d | xargs chmod 0755
Delete all filename* files under /dir directory
find /dir -name "filename*" -type f -print | xargs rm
exclude ./dirtoexclude, using yui compress all file under currect folder
find . -path "./dirtoexclude" -prune \ -o -exec java -jar config/yuicompressor-2.4.2.jar --type js '{}' -o '{}' \;
Search for 'string-to-find' in all HTML files under current directory tree and show the matched lines with their filenames
find . -name \*.html -exec grep -H string-to-find {} \;
filter output of bind -p by regex
bind -p | grep -a forward
Displays process tree of a process with id 'PID', showing parent process and processes id.
pstree -p -s PID
Find all symbolic links under current directory that are not hard links
find . -type f -links 1 -print
display all directories which have not been accessed in the last 24*3 hours
find -type d -and -atime +3
Remove all 'a.out', '*.o', and 'core' files in the current directory tree
find . \ -exec rm {} \;
Find all files/directories containing 'blah' (case insensitive) in their names that were modified in less than 2 days ago uder current directory tree
find . -iname '*blah*' -mtime -2
delete all the empty in the current folder do not search in sub directories
find . -maxdepth 1 -type d -empty -exec rm {} \;
Print all files in the current directory tree as a comma separated list
find . -type f | paste -d, -s
Display the contents of "myfile" located in the current directory.
cat myfile
Extract, sort and print only group names from /etc/group.
cut -d: -f1 /etc/group | sort
find all the normal/regular files in current folder excluding sub directories and hidden folders and display the count
find . -type f -maxdepth 1 ! -name '.*' -exec printf '%.0s.\n' {} + | wc -l
Recursively copies '../include/gtest' directory to '~/usr/gtest/include/'.
cp -r ../include/gtest ~/usr/gtest/include/
Find hard links to the same file lpi104-6/file1 in the directory tree lpi104-6
find lpi104-6 -samefile lpi104-6/file1
Search the files residing in the current directory tree whose names contain "bills" for "put"
find . -name "*bills*" -print0 | xargs -0 grep put
search for all the files which have not been modified in the last 6 months in current folder and display the total disk usage of them
find . -mtime +180 -exec du -ks {} \; | cut -f1 | awk '{total=total+$1}END{print total/1024}'
Change the group to `temp' for all files in the current directory tree that belong to group `root'
find . -group root -print | xargs chgrp temp
Search for 'string_to_find' in all files under current directory
find -type f | sed 's/./\\&/g' | xargs grep string_to_find
Copy recursively "tata/" to "tata2/" and remove read, write, and execute permission for other
rsync -avz --chmod=o-rwx -p tata/ tata2/
Rename the *.so files at level 2 of the current directory tree prepending their names with "lib"
find . -mindepth 2 -maxdepth 2 -name "*.so" -printf "mv '%h/%f' '%h/lib%f'\n" | sh
find all the direcories in the current folder
find -type d
Find all files that contain the case insensitive regex 'stringtofind' in maximum 1 level down the / directory without descending into other partitions
find / -maxdepth 1 -xdev -type f -exec grep -Zli "stringtofind" {} +
Print NS record for domain 'domain.' from 'some.other.ip.address' nameserver
dig @some.other.ip.address domain. ns
Delete all empty directories in the current directory tree
find -type d -empty -exec rmdir -vp --ignore-fail-on-non-empty {} +
Print number of lines that equal in files '/home/xyz/a.csv1' and '/home/abc/tempfile'
comm -12 <(sort -u /home/xyz/a.csv1) <(sort -u /home/abc/tempfile) | wc -l
Find all IP addresses in /etc directory files
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
display the base name of all the ".flac" files in the current folder
find . -name "*.flac" -exec basename \{\} .flac \;
Find regular files that are larger than 2GB
find . -type f -size +2G