nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Search the current directory tree for regular files whose names end with "keep.${SUFFIX}", where $SUFFIX is a shell variable
find . -type f -name "*keep.${SUFFIX}"
List each file or directory in the current directory prefixed with its filesize in MB and sorted from smallest to largest
du -smc * | sort -n
Calculate the md5 sum of all files in "/your/dir" including content and filenames
grep -ar -e . /your/dir | md5sum | cut -c-32
Find all TXT files that belong to user root
find / -user root -iname "*.txt"
display all files in the current folder ($@ contains the variables passed as argument to the function)
find . -iname "*$@*" -or -iname ".*$@*"
Print lines in file 'file' that do not match any word specified in file 'blacklist' (one word per line)
grep -w -v -f blacklist file
Search the current user's home directory and its sub-directories for any file that ends in .tar-gz and was modified after filename was last modified.
find ~/ -name *.tar.gz -newer filename
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
Find files/directories that isn't owned by the user 'apache' under /var/www
find /var/www ! -user apache -print0 | xargs -0
Find the first file/directory under current directory named 'modules' and exit with empty result
find . -name modules -exec sh -c 'exit 0' \;
Find x* files/directories under /tmp directory whose status was changed less than 1 day ago and move them to ~/play
find /tmp/ -ctime -1 -name 'x*' -print0 | xargs -r0 mv -t ~/play/
Find all *gz files under asia and emea directory and print their names and line counts to file_count.txt
find asia emea -type f -name "*gz" | while IFS= read -r fname; do printf "%s %s\n" "$fname" $ >> file_count.txt; done
Print the IP addresses for the current host name
host `hostname` | awk '{print $4}'
Create an empty file 'last.check' in directory pointed by variable "log_dir", with specified timestamp.
touch -m 201111301200.00 $log_dir/last.check
Search the /usr/ directory tree for files newer than file /tmp/stamp
find /usr -newer /tmp/stamp
Find files in the current directory tree whose size is 24000 bytes
find . -size 24000c
Find all files under current directory excluding hidden directories
find -name '.?*' -prune -o \
Change the permissions of every directory in the current directory and all files and directories within them to 700
find . -maxdepth 1 -type d -exec chmod -R 700 {} \;
Search the current directory recursively for files writable for `others'
find . -perm -o+w
Remove all Thumbs.db files under temp/images directory
find temp/images/ -type f -iname Thumbs.db | while read FILE ; do rm "${FILE}" ; done
Save absolute path of the script filename in variable "SCRIPT"
SCRIPT=$( readlink -m $)
rename all the svg.png files to png files in the current fodler
find . -name "*.svg.png" -print0 | sed 's/.svg.png//g' | xargs -0 -I namePrefix mv namePrefix.svg.png namePrefix.png
Find files in the current directory tree which have permissions rwx for user and rw for group and others
find . -perm 766
Count lines that are neither blanks nor comments in a file 'foo.pl'
cat foo.pl | sed '/^\s*#/d;/^\s*$/d' | wc -l
Remove all regular files found in and below /path
find /path -type f -exec rm '{}' +
Find files/directories in entire file system with at least 644 permission
find / -perm -644
Search the current directory recursively for regular files last changed 2 days ago
find . type -f -ctime 2
Delete all non digits from index "$i" in bash array "depsAlastmodified" and print the hex dump as characters
echo "${depsAlastmodified[$i]}" | tr -cd '[[:digit:]]' | od -c
Read a line from standard input
read
Print the second space separated fields from standard input
tr -s ' ' | cut -d ' ' -f 2
Find all *.c files under and below the current directory that contain "hogehoge"
find . -name \*.c | xargs grep hogehoge
Search the ./bin directory recursively for files called "cp"
find ./bin -name “cp”
Find all php files whose name is tecmint.php in the current directory
find . -type f -name tecmint.php
Search the current directory tree for files whose names begin with "my" and end with "p" followed by any character, ignoring path names containing "test"
find . -regex ".*/my.*p.$" -a -not -regex ".*test.*"
Find all files under /home that belong to user tecmint
find /home -user tecmint
split all files in directory "/dev/shm/split/" into pieces per 1000 lines
find /dev/shm/split/ -type f -exec split -l 1000 {} {} \;
find all the reguar/normal php files in current directory.
find . -type f -name "*.php"
Remove all .tmp files in and below /tmp
find /tmp -name "*.tmp" | xargs rm
Show the number of lines for each .php and .phtml file in the current directory tree
find . -type f \ -exec wc -l {} +;
Find all *.txt files under /foo and delete them
find /foo -name "*.txt" -delete
display the number of lines in all the header files in the current folder
find . -name "*.h" -print | xargs wc -l
Find all files/directories starting with 'readme' under '/usr/share/doc' directory tree
find /usr/share/doc -name '[Rr][Ee][Aa][Dd][Mm][Ee]*'
search for all the regular/normal mp3 files in the file system and create a directory int /mt/mp3/ with the basename of the mp3 file
find / -iname “*.mp3″ -type f -print0 | xargs -0 -I ‘{}’ mkdir -p /mnt/mp3/`basename {}`
display all the text files and pdf files in the current folder
find . \( -name "*.txt" -o -name "*.pdf" \)
Mount "cpuset" filesystem on "/cpuset/"
mount -t cpuset none /cpuset/
Prints user and group information for each logged in system user.
w | awk '{print $1}' | xargs -I '{}' id '{}'
Print the list of all subdirectories of the current directory
find . -maxdepth 1 -mindepth 1 -type d
Filnd all directory in root directory with 777 permission and change permision755 with chmod commad .
find / -type d -perm 777 -print -exec chmod 755 {} \;
Print the list of files and directories of the current directory
find . ! -name . -prune
Convert "abc" to a string of hexadecimal bytes
echo abc | od -A n -v -t x1 | tr -d ' \n'
Counts lines of myfile.txt file.
cat myfile.txt | wc -l
Print content of 'whatever' file
cat whatever | egrep 'snozzberries|$'
Find all regular files in the current directory and search them for "example"
find -maxdepth 1 -type f | xargs grep -F 'example'
Remove all .txt files in and below the current directory
find . -name "*.txt" -delete
Look for files with wide open permissions
find . -type f -perm a=rwx -exec ls -l {} \;
Merge file1 and file2 by outputting all lines where the first comma-separated field of both files matches, followed by extra fields in file1 and those in file2
join -t, < <
Recursively copies everything from '/source/path/*' to the '/destination/path/', preserving from overwriting existing files, and printing info message on each operation.
cp -Rvn /source/path/* /destination/path/
Remove regular files whose names match Perl regular expression '\w+-\d+x\d+\.\w+$' from the current directory tree
find -type f | grep -P '\w+-\d+x\d+\.\w+$' | sed -re 's//\\\1/g' | xargs rm
Create a table containing all information from S43.txt and S44.txt, merging lines where the first field of both files matches, and keeping the line that starts with "Gene" at the start of the file.
join -a1 -a2 <(sed s/^Gene/00ne/ S43.txt | sort) <(sed s/^Gene/00ne/ S44.txt | sort) | column -t | sed s/^00ne/Gene/
Find all directories under and below directory "folder_name", and change their permissions to 775
find folder_name -type d -exec chmod 775 ‘{}’ \;
Counts lines in file 'filename' ignoring empty lines and lines with spaces only.
cat 'filename' | grep '[^ ]' | wc -l
Find files modified within the past 24 hours
find . -mtime 0
Find all *.mp3 files/directories under /tmp and remove them
find /tmp -iname '*.mp3' -print0 | xargs -0 rm
Email an alert message containing the IP address of the SSH connection with attachment "tmpfile" to "[email protected]"
mail -s "Alert: SSH Access from `who | cut -d'' -f1`" -a tmpfile [email protected]
Find all files in the home directory tree that are owned by another user
find ~ ! -user ${USER}
Find all *.jpg files in */201111/* paths and numerically sort them according to the second field in the file name with a delimiter '_'
find */201111/* -name "*.jpg" | sort -t '_' -nk2
Find all directories named build under the current directory
find . -type d -name build
find all the files that have not been modified in the last 2 days
find -mtime +2
Test if "file.tar.gz" is corrupt
gunzip -t file.tar.gz
Counts all top-level files in a current folder.
ls -1 | wc -l
Search the current directory tree for regular files omitting directory `omit-directory'
find . -name omit-directory -prune -o -type f -print
Move all files and directories matching "*.boo" in the current directory to "subdir"
mv `ls *.boo` subdir
Find all directories and for each of them, print an mv command to move it to /new/location
find . -type d -execdir echo /bin/mv {} /new/location \;
search the file myfile.txt in the current folder
find . -name myfile.txt -print
Set 644 permission to all regular files under /home/my/special/folder directory
chmod 644 `find /home/my/special/folder -type f`
Find files containing `blah' in their names modified less than 2 days ago, case insensitive
find . -iname '*blah*' -mtime -2
Save the canonical path of "$dir/$file" in variable "path"
path=`readlink --canonicalize "$dir/$file"`
Find all files whose names end with "~" in the /home/peter directory tree, following symlinks, and delete them
find -L /home/peter -name *~ -exec rm '{}' +
search for the file "file1" in the entire file system
find / -name file1
Search for all jpg images on the system and archive them
find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Display the contents of "text"
cat text
change owner and group of the file "/path/to/yourapp" to root
chown -v root:root /path/to/yourapp
search in root directory downwards all files which have less than 2 links.
find / -links -2 -print
Search the local subdirectory tree of the current working directory and the /tmp directory tree for directories named mydir
find local /tmp -name mydir -type d -print
Find all directories with 755 permission and change the permission to 700
find . -type d -perm 755 -exec chmod 700 {} \;
Create all directories in the path specified by variable $tempWork
mkdir -p $tempWork
Split "${fspec}" into 6 files with about equal number of lines each and use prefix "xyzzy."
split --number=l/6 ${fspec} xyzzy.
Remove all .sh files in the current directory tree whose names begin with "new"
find . -name "new*.sh" -exec rm -f '{}' \+
find all the text files in the current folder expect those which are in the path "sk"
find . -path "./sk" -prune -o -name "*.txt" -print
Sort "file1.txt" and output the result to "file1.txt"
sort -o file1.txt file1.txt
find out what group a given user has
groups user
Find all .js files in the current directory tree that do not contain a whitespace
find . -type f -name '*.js' \
Find all files/directores under /etc filter them by searching for 'test' in their name and run the file command on each of them
find /etc -print0 | grep -azZ test | xargs -0 file
Find all fonts (in '/usr/local/fonts') that belong to the user 'warwick'
find /usr/local/fonts -user warwick
Write standard output and error of "./a.out" to standard output and to file "output"
./a.out 2>&1 | tee output
Delete all filename* files under /dir directory
find /dir -name "filename*" -type f -exec rm {} \;
Find files whose names match the pattern given by the 2nd argument $2 of the Bash script and replace string $3 with $4 in them
find ./ -type f -name "$2" -exec sed -i "s/$3/$4/g" {} \;
Print $1 if $1 is an empty directory
find "$1" -name "?*" | dd bs=$() count=1 2>/dev/null
find all the files in the current folder that have been modified in the last 24*3 hours
find ./ -mtime -3
find all the files in the current directory which have been modified after a file
find . -newer file