nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Show the mv commands that would 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" | less -S
Find all directories under and below parent_directory
find parent_directory -type d
Execute awk command '{ ...}' on compressed file "FILE"
zcat FILE | awk '{ ...}'
Find all files under $1, calculate their md5sum and redirect the result to checksums.md5
find "$1" -type f -print0 | parallel -0 -X md5 > checksums.md5
Find all .rb files owned by root in the /apps/ folder and below that have been accessed in the last two minutes.
find /apps/ -user root -type f -amin -2 -name *.rb
Saves 'ls' output together with time report to a file 'time.txt'.
{ time ls; } 2>&1 | cat > time.txt
Find all the files without permission 777
find / -type f ! -perm 777
Find & Write Changes to a File and Print the Changes Using sed s//gpw
find . -type f -name "*.txt" -exec sed -n 's/Linux/Linux-Unix/gpw output' thegeekstuff.txt
Find all *.c files under and below the current directory that contain "wait_event_interruptible"
find . -name \*.c -exec grep wait_event_interruptible {} +
display all the files in the folder /etc /srv excluding those that are present in the path of ./srv/tftp/pxelinux.cfg* and /etc/mtab
find /etc /srv \! -path "./srv/tftp/pxelinux.cfg*" -a \! -name /etc/mtab
Find all directories under current directory having DIRNAME in their name
find . -type d | grep DIRNAME
Run the file command on every regular file under current directory
find . -type f -exec file '{}' \;
List files in the current directory and below
find -ls
Write output of "command" to standard output and to "/path/to/logfile"
command | tee /path/to/logfile
Find deb packages in the current directory recursively and list them with `dpkg'
find . -type f -and -iname "*.deb" | xargs -n 1 dpkg -I
Print history with the first field removed
history | awk '{sub($1, ""); sub(/^[ \t]+/, ""); print}'
Search the current directory recursively for *.txt files with lines that match regular expression "^string"
find . -name "*.txt" -exec egrep -l '^string' {} \;
Show the last 10 .conf files found by `find' in the /etc directory and 1 level below
find /etc -maxdepth 2 -name "*.conf" | tail
Find all files/directories under whatever and ... directory and copy them to /var/tmp
find whatever ... | xargs -d "\n" cp -t /var/tmp
Search the current directory tree for files containing "needle" in their names
find . -iname "*needle*"
find all the files ending with "~" in current folder and move them to temp folder
find -name '*~' -print0 | xargs -0 -I _ mv _ /tmp/
create a compressed archive "compressFileName.tar.gz" with verbose output
tar -zcvf compressFileName.tar.gz folderToCompress
Recursively change ownership of "~/.npm" to the current user
sudo chown -R $ ~/.npm
Find all *.txt files/directories in entire file system
find / -name "*.txt"
FInd files in current directory and grep text and html files - but not index.html and report things that contain the word 'elevator' in four or more lines
find . -type f -print0 | egrep -iazZ '$' | grep -vazZ 'index.html' | xargs -n 1 -0 grep -c -Hi elevator | egrep -v ':[0123]$'
search for dbmsspool.sql file in the current folder
find . -print|grep ?i dbmspool.sql
Set trace prompt to print seconds, nnoseconds, script name, and line number
PS4='+$ %N:%i> '
display all the files in the current folder which have the permissions 777 and which have been modified in the last 24 hours.
find . -perm 777 -a -mtime 0 -a -print
Lists all subdirectories in a current folder, removing trailing slash.
ls -d */|sed 's|[/]||g'
List files larger than 10MB under /var/log
find /var/log -size +10M -ls
Test if a file named 'file' in the current directory is more than 1 hour old
find file -prune -cmin +60 -print | grep -q .
List all .jpg files in the home directory tree in a fast way
find . -name "*.jpg" -exec ls {} +
Prints path to folder that contains target of the symbolic link ../../../../etc/passwd.
$(dirname $(readlink -e ../../../../etc/passwd))
Search the /usr/bin directory tree for regular files modified or created less than 10 days ago
find /usr/bin -type f -mtime -10
Check if /path/to/file exists and has a size greater than 25600KB
[[ $ ]] && echo true || echo false
Searches through the htdocs and cgi-bin directories for files that end with the extension .cgi. When these files are found, their permission is changed to mode 755 .
find htdocs cgi-bin -name "*.cgi" -type f -exec chmod 755 {} \;
Output "testFile.txt.1" without the ".1" suffix.
basename testFile.txt.1 .1
Print common lines in files "set1" and "set2"
comm -12 <(sort set1) <(sort set2)
Use the first non-zero exit code of a set of piped commands as the exit code of the full set of commands
set -o pipefail
Executes 'sleep 10' in a subshell created by a pipeline of built-in function 'true'.
true | sleep 10
Print 10 "#" characters in a row
yes '#' | head -n 10 | tr -d '\n'
Find all directories that start with stat
find . -type d –iname stat*
Search for 'birthday' (case insensitive) in all regular files under ~/Documents directory tree and show only the filenames
find ~/Documents -type f -print0 | xargs -0 grep -il birthday
Wrap each line in "longline" to a maximum of 30 characters breaking at spaces
fold -w30 -s longline
Find all 664 permission files/drectories under current directory tree
find . -perm -664
Find all files under current directory and set read-write permission for owner, read permission for group and other for those directories
find . -type f -exec chmod u=rw,g=r,o=r {} \; - that's 644
List all files and sub directories including hidden files in the current directory tree
tree -af
display all files in the current directory excluding those that are present in the directories whose name starts with "efence" and do not search in the sub directories
find * -maxdepth 0 -name "efence*" -prune -o -print
Remove symbolic links and get absolute path of "${the_stuff_you_test}" and save to variable "DIR_PATH"
DIR_PATH=`readlink -f "${the_stuff_you_test}"`
Find all directories under $ROOT_DIR and show the sub-directories of the directories before the directories themselves
find $ROOT_DIR -type d -depth -print
Remount subtree "/outside" to "/inside" as a bind
mount /outside /inside -o bind
Save the numerically greater value of "$kf" and "$mp" into variable "gv"
gv=$(echo -e $kf'\n'$mp | sort -t'.' -g | tail -n 1)
Find all directories under /home/username/public_html/sites/default/files and set their permission to 770
find /home/username/public_html/sites/default/files -type d -exec chmod 770 {} +
If first command fails, exits from script with exit code of failed command.
echo $[4/0] || exit $?
Gets MAC address of eth0 network interface.
ifconfig eth0 | grep -Eoi [:0-9A-F:]{2}\(\:[:0-9A-F:]{2}\){5}
Print content of '1' file
$ cat 1
find all regular/normal files in the current folder and display them in the a format.
find -type f -exec perl -e 'printf qq[%s => %s\n], scalar @ARGV, length join q[ ], @ARGV' {} +
Find all regular files under current directory tree without descending into './dir1' and './dir2' directories
find . \ -prune -or -type f -print
Append the parent directory name with a space in all 'text.txt' files in all sub directories of current directory
find . -name text.txt | sed 's|.*/\/.*|sed -i "s@^@\1 @" & |' | sh
Find all regular files under current directory tree containing 'some text' in their names without descending into hidden directories and excluding hidden files
find . -type d -path '*/\.*' -prune -o -not -name '.*' -type f -name '*some text*' -print
display all normal/regular files in current folder
find . -type f
Find all files/directories named 'file' without descending into directories with the same name under current directory tree
find -name file -prune
Print a welcome message with the current user's user name
echo "Welcome `whoami`!"
Print all the file/directory paths under current directory
find | xargs
search for files cart1 or cart2 or cart3 or ...cart6 in the folder junk which is in home folder and display all its details. Discard all the errors and do not display them.
find ~/junk -name 'cart[1-6]' -exec ls -l {} \; 2> /dev/null
Identify CMS version/releases accross all your Drupal websites
find /home/*/public_html/ -type f -iwholename "*/modules/system/system.info" -exec grep -H "version = \"" {} \;
List all files in a current folder, separating names with semicolon
ls -m | tr -d ' ' | tr ',' ';'
Print the list of files in the current directory tree skipping SVN files
find . -path '*/.svn*' -prune -o -print
show all directories in the current folder excluding those that are present in the sub directories of media, images and backups
find . -type d \ -prune -o -print
Find all 50MB files in file system
find / -size 50M
search for all the mp3 files in the file system and move them to the folder /mnt/mp3
find / -iname "*.mp3" -exec mv {} /mnt/mp3 \;
Print a list of all files and directories in the /var/log directory tree
find /var/log/
Search for files which have read and write permission for their owner, and group, but which other users can read but not write to.
find . -perm 664
Finds strings like "texthere" recursively in all files of a current folder regarding all symlinks.
grep -R "texthere" *
List all files in the current directory tree that were modified 60 minutes ago
find . -mmin 60 | xargs '-rd\n' ls -l
find all the files in the file system which are bigger than 3 bytes
find / -size +3 -print
Find all of the distinct file extensions in current directory
find . -type f | perl -ne 'print $1 if m/\.$/' | sort -u;
Find all *.dbf files/directories in entire file system and print their sorted and unique parent directory paths
find / -name \*.dbf -print0 | xargs -0 -n1 dirname | sort | uniq
display a list of all files in the folder passed as argument to a script
find $@ -ls
display all the regular files in current folder
find . -type f
Display difference between one.txt and two.txt side-by-side.
diff -y one.txt two.txt
Set variable value to current kernel release name.
value=$(uname -r)
Search for 'example' in all regular files from the current directory
find -maxdepth 1 -type f | xargs grep -F 'example'
Print git branch currently checked out in a working directory.
git status --branch --porcelain | grep '##' | cut -c 4- | cut -d'.' -f1
Find files that were modified more than 7 days ago and archive them
find . -type f -mtime +7 | xargs tar -cvf `date '+%d%m%Y'_archive.tar`
Count the number of files in the /usr/ports directory tree whose names begin with 'pkg-plist' and which contain 'dirrmtry'
find /usr/ports/ -name pkg-plist\* -exec grep dirrmtry '{}' '+' | wc -l
Kill screen session 23536
screen -S 23536 -X quit
Find all files named 'aaa.txt' under current directory tree and display their contents
cat `find . -name aaa.txt`
Create thumbnails from the first page of each PDF files under /path/to/dir
find /path/to/dir -name '*.pdf' -exec convert -thumbnail x80 {}[0] {}-thumb.png \;
display all the files in the current folder excluding the files with the name mmm
find . -name mmm -prune -o -print
Search for files bigger than 10M
find ~ -size +10M
Print out all .pdf files from the current directory tree as plain text on the standard output
find . -name '*.pdf' -print0 | xargs -0 -n1 -I '{}' pdftotext '{}' -
Print and save the ping results of 25 requests to "google.com" in "/home/user/myLogFile.log" containing at most 100000 bytes
ping -c 25 google.com | tee >(split -d -b 100000 - /home/user/myLogFile.log)
Enables shell option 'promptvars'.
shopt -s promptvars
Add "prefix_" to every non-blank line in "a.txt"
nl -s "prefix_" a.txt | cut -c7-
Compress "archive.tar"
gzip archive.tar
Remove trailing spaces from all files under current directory
find . -type f -print0 | xargs -0 perl -pi -e 's/ +$//'
Print each line in "file1.txt" that is not found in "file2.txt"
sort file1.txt file2.txt file2.txt | uniq -u
Search for all non-hidden files
find . -name '*'
Search level 3 of the current directory tree for the directories whose pathnames contain "New Parts"
find -mindepth 3 -maxdepth 3 -type d | grep "New Parts"