nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Remove all broken symbolic links in /usr/ports/packages
find -L /usr/ports/packages -type l -delete
Creates temporary file with name formatted like expression in variable ${PROG}, and saves path to it in 'mytemp' variable.
mytemp="$"
Find all regular files under $dir directory tree with name pattern provided by the first positional parameter and show only the $num'th line from each of those files
find $dir -type f -name $1 -exec sed $num'q;d' {} \;
Measure the disk space taken up by all *.txt files in the current directory tree
find . -name "*.txt" -print0 |xargs -0 du -ch | tail -n1
display all the ".c" files in the current folder excluding those that are present in the .svn sub folder
find . -name .svn -prune -o -name "*.c" -print
Check if "~/mnt/sdc1" is mounted
mount | grep -q ~/mnt/sdc1
display all file in the home folder except ".c" files
find $HOME -not -iname "*.c" -print
Display a named character dump of "test.sh"
od -a test.sh
Delete all files/directories taken by the glob pattern * except the ones with the name 'b'
find * -maxdepth 0 -name 'b' -prune -o -exec rm -rf '{}' ';'
Split "date.csv" into files with at most 100 lines each
split -l 100 date.csv
Display the number of lines in all regular files under current directory tree and also show the total count
find . -type f -exec wc -l {} +
Keep the last 3 components (directories) of $path
echo $path | rev | cut -d'/' -f-3 | rev
Find files/directories named 'aaa.txt' under current directory tree
find . -name aaa.txt
find all the files in the entire file system which belong to the user with the uid 1005 and discard all the errors
find / -uid 1005 2>/dev/null
Find files on the system that are bigger than 20 megabytes
find / -type f -size +20M -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }'
display list of all the hidden files in the home folder
find $HOME -name ".*" -ls
Ungzip and untar all files matching "www-backup.tar.*"
cat www-backup.tar.*|gunzip -c |tar xvf -
Remove all but 5 last comma-separated fields from each line in 'data.csv'
cat data.csv | rev | cut -d, -f-5 | rev
change owner of the file destination_dir to user "user:
chown user destination_dir
Searches the manual page names and descriptions by 'disk' keyword.
apropos disk
find all the word press configuration php files in the folder /var/www and do not search beyond two levels
find /var/www/ -name wp-config.php -maxdepth 2
find all the files in the folder /opt which have been accessed exactly 20 days ago
find /opt -atime 20
Find all files/directories named 'foo.bar' in the entire filesystem
find / -name foo.bar -print
Replace all spaces with underscores in directory names under current directory.
find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
Displays the count of of each unique line read from standard input
sort | uniq -c
create directory /cpuset
mkdir /cpuset
display all files in current folder which have not been modified in the last 60 minutes
find -mmin +60
Print login information of all users except the first two and replace all instances of " " with ", "
who | awk '{ if {print} }' | sed -e 's/ /, /g'
change owner of the files into directory "/mydir" with ".txt" extension to user root
find /mydir -type f -name "*.txt" -execdir chown root {} ';'
Calculate md5 checksum of $line and save to variable 'md5'
md5=$
search all jpg files in current folder
find . -type f -name "*.jpg"
Counts total number of lines in all file under current folder.
find ./ -type f -exec wc -l {} \; | cut -d' ' -f1 | paste -sd+ | bc
Search the current directory tree for files containing "album" and "vacations" in their names and not containing "2015"
find . -name "*album*" -a -name "*vacations*" -a -not -name "*2015*"
Create a symbolic link named "${DESTINATION}${file}" to "${TARGET}${file}"
ln -s "${TARGET}${file}" "${DESTINATION}${file}"
Find all files under current directory and replace the match of the regex '^.*/S' with 'S' in every line of the output
find . -type f -print | sed 's|^.*/S|S|'
Copy all *.data files under jcho directory to files whose names are constructed by replacing the first '0' to '2' in their names
find jcho -name *.data -exec sh -c 'f="${0}"; d=$; cp ${f} ${d} ' {} \;
display all regular files in current folder which are atleast 1 level deep and search in the alphabetical order of the directories
find -ds . -mindepth 1 -type f -print0; printf '\0';
Recursively lists all files in a current folder in long format, sorting by modification time.
ls -ldt $(find .)
Remount "/dev/sda7" partition as executable
sudo mount -o remount -o exec /dev/sda7
find all the files in the home folder which have not been modified in the last 1 year.
find $HOME -mtime +365
Find symlinks under and below the "test" directory and replace them with the content of the linked files
find test -type l -exec cp {} {}.tmp$$ \; -exec mv {}.tmp$$ {} \;
Silently download contents from https://raw.github.com/Homebrew/homebrew/go/install and show an error if failed, execute with ruby after the download is completed
ruby -e "$"
display a long listing of all the files in the current folder which have been modified in the last 24 hours
find . -mtime -1 | xargs ls -ld
Saves list of logged in users in system together with 'USER' header in the 'b' variable.
b=`w|cut -d' ' -f1`;
Print "echo ping -c 2" on each string in file 'ips'
cat ips | xargs echo ping -c 2
Print which files differ between dir1 and dir2, treating absent files as empty
diff --brief -Nr dir1/ dir2/
Find all regular files starting from level 3 of directory tree ~/container and move them to the current directory
find ~/container -mindepth 3 -type f -exec mv {} . \;
Replace all negative numbers in the 3rd comma-separated column of inputfile by the number notated in parenthesis instead of with a minus sign.
awk -F, 'BEGIN {OFS = ","} {gsub("-([0-9.]+)", "(" substr($3, 2) ")", $3); print}' inputfile
display list of all the files in the /tmp folder
find /tmp/ -exec ls "{}" +
Report file systems disk usage using POSIX output format.
df -P
Remove trailing spaces and tabs from all *.java files under current directory
find . -type f -name "*.java" -exec perl -p -i -e "s/[ \t]$//g" {} \;
Locate files that reside in the home directory and have not been accessed in the past 30 days
find $HOME -atime +30
Find files modified at least 5 days in the future
find . -newermt "5 days"
split file /usr/bin/firefox into pieces per 1000 lines
split -n 1000 /usr/bin/firefox
Change all file permissions to 664 and all directory permissions to 775 in directory tree "htdocs"
find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +
Read a line from standard input into variable "REPLY" with prompt "$1 : "
read -p "$1 : "
find all the files in the current directory and display them
find . -exec echo {} ;
find all the files in the current folder which are readable
find . -readable
Print files created/modified in the last day
find /directory -newermt $(date +%Y-%m-%d -d '1 day ago') -type f -print
Find all syslog directories under /var/log directory
find /var/log -name "syslog" -type d
find the oldest normal file in the current directory and display with its timestamp
find ! -type d -printf "%T@ %p\n" | sort -n | head -n1
Find all files/directories in current directory and execute myscript with minimal invocation for those files/directories
find . -exec myscript {} +
print readline bindings that use key code '\\e\\C-k'
bind -P | grep '\\e\\C-k'
Print the file 'text1;text2;text3' replacing each space(" ") with a newline
cat "text1;text2;text3" | sed -e 's/ /\n/g'
Get the disk space used by all *.txt files/directories under current directory
find . -iname "*.txt" -exec du -b {} + | awk '{total += $1} END {print total}'
search for the file "filename" in the entire file system
find / -name filename
Unzip all files matching "file_*" and pipe into "agrep -dEOE 'grep'"
find -name 'file_*' -follow -type f -exec zcat {} \; | agrep -dEOE 'grep'
find all regular/normal files in the current folder
find -type f
Find all the files which are accessed 50 days back
find / -atime 50
find all the directories in the $LOGDIR folder which have been modified in the last 24 hours and compress them
find $LOGDIR -type d -mtime +0 -exec compress -r {} \;
Locate all the hard links of file `passwd'
find / -samefile passwd
Number every line of standard input as zero padded to 6 characters followed by "-"
nl -s- -ba -nrz
Find and list all files on your current directory and show a few lines of output from the beginning
find | head
Archive all *.xml files under current directory tree to xml.tar excluding the files that match '/workspace/' in their paths
find . -name \*.xml | grep -v /workspace/ | tr '\n' '\0' | xargs -0 tar -cf xml.tar
Find all files/directories under current directory and print their paths
find . -exec echo {} ";"
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 {} \;
remove all the files in the present directory which have space in their name.
find . -name "* *" -exec rm -f {} \;
Remove the "^M" characters from all *.ext files under /home directory
find /home -type f -name "*.ext" -exec sed -i -e 's/^M$//' {} \;
create directory aaa/bbb
mkdir aaa/bbb
Counts lines in each *.php file.
wc -l `tree -if --noreport | grep -e'\.php$'`
Recursively change owner of all files in "folder" to "user_name"
chown -R user_name folder
View history using "vim"
history | vim -
Find all files/directories that contain the string literal '$VERSION' in their names under current directory tree
find . -name '*$VERSION*'
Send one ping request to host with local address in the 10.0.0.x range, with last number specified by variable "i", waiting 1 second for a reply, and output only lines containing "from" to standard output.
ping -W 1 -c 1 10.0.0.$i | grep 'from' &
Read all *.txt file paths under /foo into a Bash array
IFS=$'\n' read -d '' -ra files < <
Count the number of matches for the regex '\<exception\>' in all *.txt files under /usr/share/doc/ directory
cat $ | zegrep -ic '\<exception\>'
Calculate md5 checksum of the list of all files/dirs in /path recursively including dot files and excluding the patterns 'run', 'sys', 'tmp' and 'proc', then check the checksum against the checksum saved in /tmp/file
ls -alR -I dev -I run -I sys -I tmp -I proc /path | md5sum -c /tmp/file
Find all directories name nasa in the current directory and below.
find . -name nasa -type d
display a long listing of all images with the name "articles" in the current folder
find . -iname "Articles.jpg" -exec ls -l {} \;
Split "$1" into files of at most "$2" or default 10000 using a numeric suffix of length 6
split -l ${2:-10000} -d -a 6 "$1"
Find all files larger than 20000k
find / -type f -size +20000k
display all directories in the folder "/myfiles"
find /myfiles -type d
Mount remote "cifs" filesystem "//192.168.0.111/serv_share" on "/mnt/my_share" with username "me" and password "mine"
sudo mount -t cifs -o username=me,password=mine //192.168.0.111/serv_share /mnt/my_share
Find files recursively with extension "ext"
find . -name "*.ext"
ssh into default vagrant host without running "vagrant ssh"
ssh `vagrant ssh-config | tail -8 | perl -pe 's/^\s+/-o@/; s/\s/\=/;s/@/ /;s/\n/ /'` vagrant@localhost
Print yesterday's date as yyy:mm:dd
date +%Y:%m:%d -d "1 day ago"
Find all .txt files in the dir/ directory tree and copy them along with times, permissions, and ownership to dir_txt/
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ --parents
find all regex "./[a-f0-9\-]\{36\}\.jpg" files
find . -regex "./[a-f0-9\-]\{36\}\.jpg"
find all text files which have extra extensions in the current folder
find . -name '*.text' -exec $SHELL -c '[ ! -f ${1%.*} ]' $SHELL '{}' ';' -print
Print full date of yesterday
echo `date -v-1d +%F`