nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
list all the ".ksh" files in the current directory
find . -ls -name "*.ksh"
Creates temporary file by template provided in option '-t'.
mktemp -t identifier.XXXXXXXXXX
Search the current directory tree for regular files that contain "string"
find . -type f | xargs grep string
find all the files in the directory which is pointed by $1 variable ending with the name held in the variable $2 or having the extension of value saved in the argument $2.
find $1 \ -print
Recursively changes group ownership of everything in a '/home/user1/project/dev' folder to 'project_dev'.
chgrp -R project_dev /home/user1/project/dev
Measure the disk space taken up by all *.txt files in the current directory tree
find . -name "*.txt" -print0 |xargs -0 du -ch
display all the files in the home folder which have read permission to the user
find /home -perm /u=r
Search the current directory for all files with no 'read' privilege for 'others'
find . -maxdepth 1 ! -perm -o=r
Find links to any file that happens to be named `foo.txt'
find . -lname \*foo.txt
search in the current folder for all the directories with the name "test"
find . -type d -name test
List empty directories in the current directory tree
find . -depth -empty -type d
Handles shell option 'nullglob' according with flags stored in $NGV variable.
shopt "$NGV" nullglob
Print the time of last boot
who -b
find all the files and folder that were created in 2012 on Friday of every month
find / -daystart -mtime +41 -mtime -408 \ -printf "%M %n %u %g %10s %TY-%Tm-%Td %Ta %TH:%TM:%TS %h/%f\n" | awk '($7=="Fri"){print}'
Prepends date to ping output
ping www.google.com | while read endlooop; do echo "$: $endlooop"; done
Recursively list all the files and directories that are only in directory /dir1 with their full paths.
diff -rq /dir1 /dir2 | grep -E "^Only in /dir1.*" | sed -n 's/://p' | awk '{print $3"/"$4}'
Make directory "~/log"
mkdir ~/log
Mathematically add each line in "filename"
paste -sd+ filename | bc
Find all .txt files of user Tecmint under /home directory
find /home -user tecmint -iname "*.txt"
Find all directories under maximum 1 level down the /parent directory and set their permission to 700 recursively
find /parent -maxdepth 1 -type d -print0 | xargs -0 chmod -R 700
Save the canonical filename of the script in variable "me"
me=$
find all the html files in the current folder and delete a line
find ./ -type f -name '*.html' | xargs sed -i '1,/sblmtitle/d'
find the oldest normal file in the current directory and display its contents
find -type f -printf "%T+ %p\0" | sort -z | grep -zom 1 ".*" | cat
List all entry names contained directly by directory in_save in the current directory, pausing for user input at each page.
find ./in_save/ -type f -maxdepth 1| more
Delete all files/directories under current directory tree with '.$1' extension where $1 expands as the first positional parameter
find . -name "*.$1" -delete;
find all the files ending with .mp3 or .jpg
find . \ -print
delete all the mp3 files in the current folder.
find . -type f -name "*.mp3" -exec rm -f {} \;
find all the files that have been modified exactly 24 hours ago
find . -type f -mtime 1
display all the empty files in the current folder( files of size 0 bytes)
find . -empty
Search for 'organic' in all files with '.html' extension under ~/html directory
find ~/html/ -name '*.html' -exec grep organic '{}' ';'
Prints what day it was 222 days ago
date --date="222 days ago" +"%d"
Add variable 'v' with value '5' to a temporary environment, list this environment using 'less' to interactively view it.
v=5 env|less
Check the syntax of all PHP files under the current directory
find . -type f -name "*.php" -exec php -l {} \;
remove all the files in the folder "myfiiles" which have not been accessed in the last 30*24 hours
find /myfiles -atime +30 -exec rm {} ;
Print mv commands to rename all files under current directory by formatting the filenames with the sed scripts '\''s/^-\s*/\L\1\E-\2/'\'', '\''s/ /_/g'\'' and '\''s/_-/-/g'\''
find ./ -type f -exec bash -c 'echo "mv \"$1\" \"$(echo "$1" | sed -re '\''s/^-\s*/\L\1\E-\2/'\'' -e '\''s/ /_/g'\'' -e '\''s/_-/-/g'\'')\""' - {} \;
Print only common strings in sorted content of files 'file1' and 'file2'
comm -1 -2 < <
search all files in the current folder which match the regular expression
find . -regex ".*/my.*p.$" -a -not -regex ".*test.*"
search for the word bananas in the all the regular/normal files in the entire file system
find / -type f -exec grep bananas {} \; -print
Set the executable bit for all users on all regular files from directories arch/x86/usr/sbin, arch/x86/usr/X11R6/bin, usr/sbin/
find arch/x86/usr/sbin arch/x86/usr/X11R6/bin usr/sbin/ -type f | xargs chmod a+x
SSH into "hostname" on port 22 as user "myName"
ssh -p 22 myName@hostname
Compresses with compression level 9 all files under the current folder but already compressed '*.bz2' files, performing in background.
find "$1" -type f | egrep -v '\.bz2' | xargs bzip2 -9 &
Print "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" and append to file "/etc/apt/sources.list"
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
Recursively archive "test/a/" to "test/dest" excluding "test/a/b/c/d"
rsync -nvraL test/a/ test/dest --exclude=/b/c/d
find all the html files that are acces in the last 24 hours in the current folder
find . -mtime 1 -name "*.html" -print
Replace all occurrences of foo with bar in all *.css files under %s directory
find %s -iname *.css | xargs sed -i s/[Ff][Oo][Oo]/bar/g
Write the standard output and error of "program.sh" to console and append to "log"
progam.sh 2>&1 | tee -a log
find all the files in the current folder which are exactly 1234 bytes
find . -size 1234c
find all the files starting with "config" in the folder Symfony ( case insensitive search)
find Symfony -iname '*config*';
find C, C++ source and header files in current folder and create etags for them
find . -type f -print | xargs etags -a
Find all *.jpg files under current directory and print only unique names
find . -name *.jpg | uniq -u
Print short TXT record of domain o-o.myaddr.l.google.com from nameserver 8.8.8.8
dig TXT +short o-o.myaddr.l.google.com @8.8.8.8
Find all directories named 'local' in entire file system
find / -name local -type d
list all files
find .
Save the list of all .py files under and below the current directory that contain "something" in their pathnames to output.txt
find . -name '*.py' | tee output.txt | xargs grep 'something'
Find all the files which were modified more than 50 days but less than 100 days ago
find / -mtime +50 -mtime -100
find all files that are readable or writable by their owner
find . -perm +600 -print
calculate the total size of jpg files in current folder
find . -name "*jpg" -exec du -k {} \; | awk '{ total += $1 } END { print total/1024 " Mb total" }'
Split "$in_file" excluding the first line into files of at most 100000 lines each with numeric suffixes of length 5 and the prefix $in_file"_"
awk '{if (NR!=1) {print}}' $in_file | split -d -a 5 -l 100000 - $in_file"_"
display all the files in the current folder which contains form feed and does not contain NULL
find . | xargs grep -PL "\x00" | xargs grep -Pl "\x0c"
Find all broken symlinks under current directory
find . -type l -xtype l
Print the list of files in the current directory tree ignoring .svn, .git, and other hidden directories
find . -type f -not -path '*/\.*'
list all files under the current directory, writing the output to the file files_and_folders
find . > files_and_folders
List all files in entire file system that are newer than the file $newerthan and older than the file $olderthan and sort them according to file modification time
find / -type f -name "*" -newermt "$newerthan" ! -newermt "$olderthan" -printf "%T+\t%p\n" | sort | awk '{print $2}'
replace the word foo to bar in the current folder in all the regular/normal files which have execute permission
find . -type f -executable -exec sed -i 's/foo/bar/g' {} +
display all the files in the folders /etc /srv excluding the paths /etc/mtab and /srv/tftp/pxelinux.cfg
find /etc /srv \ -prune -o -print
Print the kernel configuration options found in "/proc/config.gz"
cat /proc/config.gz | gunzip
List all files under the current working directory with name ".htaccess"
find `pwd` -name .htaccess
Find all files under ~/code that are executable by owner without descending into hidden directories and print their parent directories appended with : at the beginning and remove all newlines and the last :
find ~/code -name '.*' -prune -o -type f -a -perm /u+x -print | sed 's@/[^/]\+$@:@' | sort | uniq | tr -d '\n' | sed 's/^/:/; s/:$//'
display the number of lines in all the ".c" files in the current folder
find . -name "*.c" -print | xargs wc -l
Convert all markdown files on the system to html
find / -name "*.md" -type f -exec sh -c 'markdown "$0" > "$0.html"' {} \;
Moves the file that named like file $1 from '/tmp' folder to the folder where $2 file is located.
mv "/tmp/`basename $1`" "`dirname $2`"
Search the current directory tree for files and directories whose names do not end in ".exe" and ".dll"
find . -not -name "*.exe" -not -name "*.dll"
display all the files ending with ".user" in /var/adm/logs/morelogs/ and excluding all regular files
find /var/adm/logs/morelogs/* -type f -prune -name "*.user" -print
Changes group ownership of '/var/run/fcgiwrap.socket' to 'forge'.
chgrp forge /var/run/fcgiwrap.socket
recursively change owner and group of the directory /vol/html and all files into it to user ec2-user and group apache
sudo chown -R ec2-user:apache /vol/html
create a compressed archive excluding files matching a pattern
tar -czf backup.tar.gz --exclude=PATTERN1 --exclude=PATTERN2 ... /path/to/backup
Find all *.data files under jcho directory
find jcho -name *.data
Convert all characters in "$a" to lower case and save to variable "b"
b=`echo "$a" | sed 's/./\L&/g'`
get md5sum of an iso file without displaying the filename, save value to 'md5' variable
md5=`md5sum ${my_iso_file} | awk '{ print $1 }'`
Delete files "*doc copoy" in directory tree /mnt/zip
find /mnt/zip -name "*doc copy" -execdir rm "{}" \;
Find PHP files containing 2 or more classes
find . -type f -name "*.php" -exec grep --with-filename -c "^class " {} \; | grep ":[2-99]" | sort -t ":" -k 2 -n -r
Recursively add user write permission to all files under "/path/to/git/repo/objects"
chmod -Rf u+w /path/to/git/repo/objects
Find all files/directories newer than ttt or owned by user 'wn' in entire file system
find / \( -newer ttt -or -user wnj \) -print
find all the files in the home folder that are modified day before yesterday
find $HOME -mtime -2 -mtime +1
Find all files in the current directory and its sub-directories that have not been assessed in more than 30 days.
find . -atime +30 -print
find all files that names are dir-name-here
find / -name "dir-name-here"
Count the number of files named `file1'
find -name file1 | wc -l
Search for all *.conf files in entire file system
find / -type f -name "*.conf"
Print a list of all *.code files from the current directory tree
find . -name *.code
display all files in current directory discard any errors and save the output to a file
find . 2>/dev/null > files_and_folders
Save the number of records in the system hostname that contain numbers in variable "server_id"
server_id=`hostname | tr 'A-Za-z-.' ' ' | tr -d '[[:space:]]' | awk '{print NR}'`
Search for the string 'device' in all regular files in the entire filesystem
find / -type f -print | xargs grep "device"
Sorts content of the $tmp file and filters out all strings with ':0'.
sort $tmp | grep -v ':0' #... handle as required
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' {} \+
display the count of total number of empty files in the current folder
find . -type f -empty | wc -l
Set permissions to 700 for directories under var/
find var/ -type d -exec chmod 700 {} \;
Find image files and move them to the pictures directory
find ~/Desktop -name “*.jpg” -o -name “*.gif” -o -name “*.png” -print0 | xargs -0 mv –target-directory ~/Pictures
Exclude directory from find . command
find -name "*.js" -not -path "./directory/*"
Upgrades 'php-mbstring' package, enabling 'remi' repository.
yum --enablerepo=remi upgrade php-mbstring
find the biggest files only
find . -type f -exec du -Sh {} + | sort -rh | head -n 15