nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Show the last 10 .conf files found by `find' in the /etc directory
find /etc -maxdepth 1 -name "*.conf" | tail
Calculate the sum of all the numbers from 1 to 10
seq 10 | jq -s 'add'
Silently read exactly 1 character ignoring any delimiters into variable "SELECT"
read -s -N 1 SELECT
find file end with '.txt' in current directory.
find . -name "*.txt"
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 -type f -exec ls -l {} \;
Print the ping time of a single request to "8.8.8.8"
ping -c 1 8.8.8.8 | awk 'FNR == 2 { print $ }'
Search the current directory tree for files containing "bash" in their names
find . -name "*bash*" | xargs
Find files in the current directory tree of size between 700k and 1000k
find . \( -size +700k -and -size -1000k \)
display all the regular files in current folder excluding all the directories and all the sub directories having "normal" in their name
find . \( \ -o -path "*normal*" \) -prune -o \ -print
Print the names of all files and directories in the current directory tree
find . -print
Add '.avi' extension to all files/directories with '.mkv' extension under '/volume1/uploads' directory tree
find /volume1/uploads -name "*.mkv" -exec mv \{\} \{\}.avi \;
find all the normal/regular files in the current directory
find -type f
display the list of all the files in the current directory which have been accssed in the last 500 days exluding hidden files
find . -type f \ -mtime +500 -exec ls {} \;
Search for the regex ... in the manual of the find command
man find | grep ...
List the files from the current directory tree that contain lines matching regular expression '^From:.*unique sender', ignoring ~/src and ~/bin
find . -name bin -prune -o -name src -prune -o -type f -print | xargs egrep -il '^From:.*unique sender'
Load keybindings from a file ~/.inputrc
bind -f ~/.inputrc
List the directory paths of all file.ext files under present working directory
find `pwd` -name file.ext |xargs -l1 dirname
Print the last 10 lines of "great-big-file.log"
tail great-big-file.log
Make directorie 'es/LC_MESSAGES' as needed in the current directory
mkdir -p es/LC_MESSAGES
Delete all empty directories under root
find root -type -d -empty -delete
Print the calendar for February 1956
cal 02 1956
search for a shell script in the current folder and display the current folder path but search from the sub directories
find . -name onlyme.sh -execdir pwd \;
search for all regular/normal files in current folder and display all the files which contain 16 lines
find . -type f -print0 | xargs -0 grep -cH '' | awk -F: '$2==16'
Search the /path directory tree for files that do not have a valid user or group
find /path -nouser -or -nogroup
find files ending with .jpg
find . -name '*.jpg' -print ./bar/foo.jpg
lists txt or html files older than 5 days, null separated
find . \( -name '*.txt' -o -name '*.html' \) -mtime +5 -print0
Find files/directories writable by group and others under the /path directory
find /path -perm -022
Remove all *.txt files in the home directory tree with confirmation
find $HOME/. -name *.txt -ok rm {} \;
Remove all directories called "test" from the current directory tree
find -path "*/test/*" -delete
find all the patch files in current folder and copy them to separate folder patches
find -name '*.patch' -print0 | xargs -0 -I {} cp {} patches/
Print output of command "stdbuf -o 0 ./a" to standard output and "output.txt"
stdbuf -o 0 ./a | tee output.txt
Counts lines of myfile.txt file.
cat myfile.txt | wc -l
copy all the regular files in the current directory to the temporary diectory.
find . -type f -exec cp {} /tmp +
Print lines in the sorted contents of "file1" that are not in the sorted contents of "file2"
comm -23 <(sort file1) <(sort file2)
Find file size in blocks
du -s <file>
excute script makeallsizes with all '*.jpg' file under originals directory in 2 processes parallelly
find originals -name '*.jpg' | xargs -1 -P 2 makeallsizes
Count the number of files/directories with '.php' extension under current directory tree and change the permissions to 755
find . -name "*.php" -exec chmod 755 {} \; -exec /bin/echo {} \; | wc -l
Change directory to the directory containing the "oracle" executable
cd $
display all instances of the file tkConfig.sh in the folder /usr
find /usr -name tkConfig.sh
Save the logical current working directory to variable "basedir"
basedir=$
create backup of all the text files present in the current folder
find -name "*.txt" cp {} {}.bkup \;
Search .c and .h files in the current directory tree for "expr"
find . -name '*.[ch]' | xargs grep -E 'expr'
Print the compressed size, uncompressed size, compression ratio, and uncompressed filename of "file.zip"
gunzip -l file.zip
Find all directories under $FOLDER, take the first fields (dot as the delimiter) from their timestamps and reverse sort them numerically
find "$FOLDER" -type d -printf "%T@\n" | cut -f 1 -d . | sort -nr
Find all the regular files under '/your/dir' directory tree which are bigger than 5 MB and display them in decreasing order of their sizes
find /your/dir -type f -size +5M -exec du -h '{}' + | sort -hr
Find all files with the SUID bit set beginning with the root directory
find / -perm -u+s
Print the last 10 commands in history
history | tail
find all the files which have not been modified in the last 1 year and display the total disk usage of them in GB
find . -type f -mtime +356 -printf '%s\n' | awk '{a+=$1;} END {printf "%.1f GB\n", a/2**30;}'
Print a colon-separated list of all directories from the ~/code directory tree, except hidden ones and those below them
find ~/code -name '.*' -prune -o -type d -printf ':%p'
Display 798 backwards
echo 798|rev
Extract 8 bytes as an unsigned integer that is "$o" offset into "$pkg"
set `od -j $o -N 8 -t u1 $pkg`
find all files in the current folder which have been modified in the last 24 hours and whose file name is of length 1
find . -name \? -mtime -1
change the permission of all the rpm files in the entire file system to 755
find / -name *.rpm -exec chmod 755 '{}' \;
split file /usr/bin/gcc into pieces per 100000 lines
split -n 100000 /usr/bin/gcc
Display standard input as a table with "${tab}" separators
column -s"${tab}" -t
Update timestamps of all files in entire filesystem which are not newer than /tmp/timestamp
find / ! -newer /tmp/timestamp -exec touch {} \;
Print which files differ in "dir1" and "dir2" recursively
diff -qr dir1/ dir2/
Search the /mnt/raid/upload directory tree for files that have not been modified within the last 5 days
find /mnt/raid/upload -mtime +5 -print
Read a line from standard input into variable "dir"
read dir
Find .java files in the current directory tree that contain 'TODO', and print their names
find . -name "*.java" -exec grep -Hin TODO {} + | basename `cut -d ":" -f 1`
Find all files in current directory that were modified less than 1 day ago excluding hidden files and put the output to full_backup_dir variable
full_backup_dir=$(find . -depth \ -prune -o -mtime -1 -print)
delete all the files in the current folder which are bigger than 1KB
find . -size +1024 ?print|xargs -i rm \;
Set the setup connection timeout to 3 seconds for connecting to "user@ip" via ssh
ssh -o ConnectTimeout=3 user@ip
Find files in the current directory tree whose pathnames contain "sub"
find ./ | grep "sub"
Replace "foo" with "bar" in all files in the current directory tree except hidden ones
find . -type f -not -name “.*” -print | xargs sed -i ‘s/foo/bar/g’
Search for 'Processed Files' in all $srch* files under current directory run the sed script 'N;s/\n/\2 \1/' on the output
find . -iname "$srch*" -exec grep "Processed Files" {} \; -print| sed -r 'N;s/\n/\2 \1/'
Print the average time of 4 ping requests to "www.stackoverflow.com"
ping -c 4 www.stackoverflow.com | sed '$!d;s|.*/\([0-9.]*\)/.*|\1|'
Find all directories in /var/www/html/zip/data/*/*/*/*/* that are older than 90 days and print only unique paths
find /var/www/html/zip/data -type d -mtime +90 | uniq
create a backup of all the files in the current folder excluding those that are present in the .snapshot sub directory and excluding the swap files
find . -name .snapshot -prune -o \ | cpio -pmd0 /dest-dir
Search for all files named foo, FOO, or any other combination of uppercase and lowercase characters beneath the current directory.
find . -iname foo -type f
Find files that don’t have 644 permissions
find / -type f ! -perm 644
Check all .txt files whose names may contain spaces whether they contain "needle"
find . -type f -iname "*.txt" -print0 | xargs -0 grep "needle"
Move all files not matching "Tux.png" in "~/Linux/Old" to "~/Linux/New/" using zsh with "EXTENDED_GLOB"
mv ~/Linux/Old/^Tux.png ~/Linux/New/
display all the java, xml and action scripts (.as) files in a directory
find dir1 -type f -a \( -name "*.java" -o -name "*.as" -o -name "*.xml" \)
Find all regular files under current directory tree that contain 'some text' in their names excluding paths that contain dot files/directories
find . -not -path '*/\.*' -type f -name '*some text*'
Remove all files matching the pattern *[+{;"\\=?~<>&*|$ ]* under current directory
find . -name '*[+{;"\\=?~<>&*|$ ]*' -exec rm -f '{}' \;
Find user daniel's files of type jpeg
find . -user daniel -type f -name *.jpg
Save the user name of the current user to variable "x"
x=$(whoami)
Search the current directory tree for regular files omitting directory `omit-directory'
find . -name omit-directory -prune -o -type f
find all the files that have been modified in the last 24 hours
find . -type f -mtime -1
Rename all *$lower1* files under current directory without descending into .git directory by replacing the first occurrence of $lower1 with $lower2 in their paths
find . -name .git -prune -o type f -name "*$lower1*" -exec mmv "*$lower1*" "#1$lower2#2" {} +
Search all regular files in the /var/log directory tree for string "19:26"
find /var/log/ -type f -exec grep -H ‘19:26′ {} \;
Remove files erroneously named `-F'
find . -name "-F" -exec rm {} \;
Recursively search current directory for all files with name ending with ".t1", change this to .t2
find . -name "*.t1" -exec rename 's/\.t1$/.t2/' '{}' \;
Recursively compress every file in the current directory tree and keep the original file
gzip -kr .
Read first column of each row, find all other first columns which have a difference less than 10, and append that comma separated list to the row
awk 'FNR==NR { array[$1]++; next } { n = asorti(array,sort); for (i=1; i<=n; i++) if (sort[i] <= $1 + 10 && sort[i] >= $1 - 10 && $1 != sort[i]) line = (line ? line "," : line) sort[i]; print $0, line; line = "" }' file.txt{,} | column -t
display all the files in the home folder excluding directories which have been modified in the last 24 hours
find /home/ -mtime -1 \! -type d
Find all regular files starting from level 3 of directory tree ~/container and move them one level up
find ~/container -mindepth 3 -type f | while read file; do mv "$file" "$/.."; done
Prints folder path where $mystring file is located.
echo dirname: $(dirname $mystring)
Look for `regexp' in binary files
find . -type f -print|xargs file|grep -i text|cut -fl -d: | xargs grep regexp
display all the java script files in the current folder
find . -name "*.js"
find all the png files in the current folder which are present in the pattern list search .txt
find . -name '*.png' | grep -f search.txt
Count the number of regular files with 755 permission under current directory tree
find . -type f -perm 755 | wc -l
Search for 'Processed Files' in all $srch* (case insensitive) files under current directory
find . -iname "$srch*" -exec grep "Processed Files" {} \; -print
Replace the leading spaces in the output of "history" with periods
history | sed 's/^ */&\n/; :a; s/ \(.*\n\)/.\1/; ta; s/\n//'
find all the files in the entire file system that have been changed exactly 60 days and display ten files
find / -cmin -60 | head
FInd all .txt files from current directory , Redirecting errors to /dev/null
find . -name "*.txt" 2>>/dev/null
Delete files in /var/tmp/stuff and below that have not been modified in over 90 days
find /var/tmp/stuff -mtime +90 -print0 | xargs -0 /bin/rm
Delete all files in the $DIR directory that have not been accessed in 5 or more days.
find "$DIR" -type f -atime +5 -exec rm {} \;
Find all 664 permission files/drectories under current directory tree
find . -perm -664