nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Compress and display the original filename of every file on the system that is greater than 100000 bytes and ends in ".log"
sudo find / -xdev -type f -size +100000 -name "*.log" -exec gzip {} \; -exec echo {} \;
search for a word in all the files in the current directory
find . -exec grep chrome {} +
Delete all regular files named 'FindCommandExamples.txt' under current directory tree
find . -type f -name "FindCommandExamples.txt" -exec rm -f {} \;
Check if process ID 1 exists (init or systemd) and current user has permission to send it signals.
kill -0 1
Find and remove all .core files
find / -name "*.core" -print -exec rm {} \;
Find all files that belongs to user Tecmint under /home directory
find /home -user tecmint
split file "${fspec} into pieces named as "xyzzyNNN" with numeric prefix from 1 to 6
split --number=l/6 ${fspec} xyzzy.
find all the files in home folder which have been modified in the last 24 hours
find $HOME -mtime -1
Remove trailing white spaces from all *.rb files under current directory
find . -name '*.rb' | xargs -I{} sed -i '' 's/[[:space:]]*$//g' {}
Reversibly sorts content of the '${TMP}/${SCRIPT_NAME}.kb' file, comparing human readable numbers in file strings.
cat ${TMP}/${SCRIPT_NAME}.kb|sort -rh;
Create empty file named with full timestamp .
touch filename_`/bin/date +%Y%m%d%H%M%S`.txt
Find files under /usr that are newer than the first file `FirstFile'
find /usr -newer /usr/FirstFile -print
Show a long listing of the latest file or directory under current directory
ls -lrt | tail -n1
Find all SGID set files under current directory and show a few lines of output from the beginning
find . -perm /g+s | head
Write "2-1" to standard output and to "/sys/bus/usb/drivers/usb/unbind"
echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
split content of the files *.txt beginning with 1001st line into pieces per 1000 lines
cat *.txt | tail -n +1001 | split --lines=1000
Save yesterday's date into variable "dt" using perl
perl -e '@T=localtime;printf' | read dt
Print a colon-separated list of all directories from the $root directory tree, except those matching pattern ".[a-z]*"
find "$root" -name ".[a-z]*" -prune -o -type d -printf '%p:'
Catch output from a script printing to /dev/tty
screen -D -m yourEvilProgram
Remount subtree "/outside" to "/inside" as a bind
mount /outside /inside -o bind
find all the files in the current folder and search for the word "vps admin" in them.
find . -exec grep -i "vds admin" {} \;
Find all broken symlinks including cyclic links under /path/to/search directory
find /path/to/search -type l -exec test ! -e {} \; -print
Find all *.m4a files under /home/family/Music directory and convert them to ogg
find /home/family/Music -name '*.m4a' -exec sh -c 'ffmpeg -i "$0" -acodec libvorbis -aq 6 -vn -ac 2 "${0%.m4a}.ogg"' '{}' \;
Calculate the md5 sum of all ".py" files in "/your/dir" including content and filenames
grep -ar -e . --include="*.py" /your/dir | md5sum | cut -c-32
Find all files matching the pattern "${pattern}" in their name and execute ${my_command} for each of them with the file path as argument
find ${directory} -name "${pattern}" -print0 | xargs -0 ${my_command}
Copy all *.data files under /source_path to /target_path
find /source_path -name *.data -exec cp {} /target_path \;
search all undo files in the current folder and calculate the total size of them
find -name '*.undo' -exec wc -c {} + | tail -n 1
search for a specific word in all files beginning with a specific word in the current directory
find -name 'file_*' -follow -type f -exec zcat {} \; | agrep -dEOE 'grep'
display all the html files in the current folder that have been modified exactly 7*24 hours ago
find . -mtime 7 -name "*.html" -print
find all the files in the current directory with the name "wagoneer" which are in the current device.
find . -xdev -name "wagoneer*" -print
Calculate the factorial of 500
seq -s "*" 1 500 |bc
find all the java script files in a folder and save the list to a file
find src/js -type f -name "*.js" > list.txt
Recursively print all files and directories in the directory tree "$absolute/path/of/your/dir"
tree $absolute/path/of/your/dir
Request DNS record for domain 'dragon-architect.com' with tracing and additional section, and extract third block of text, separated between two new lines.
dig +trace +additional dragon-architect.com | awk 'NR==3' RS="\n\n"
find foo, Foo, FOo, FOO, etc., but only dirs
find . -iname foo -type d
Find all symbolic links under the current folder and below
find –L –xtype l
Copies 'src' to 'dest' preserving overwriting the existing files.
cp -n src dest
Archive all filepattern-*2009* files/directories under data/ into 2009.tar
find data/ -name 'filepattern-*2009*' -exec tar uf 2009.tar '{}' +
Find all files/directories that were modified after February 1st under '/usr' directory tree
find /usr -newermt "Feb 1"
Find all regular files in the "aaa" directory
find aaa/ -maxdepth 1 -type f
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
Gets domain name from dig reverse lookup.
$dig -x 8.8.8.8 | grep PTR | grep -o google.*
Replace all instances of "STRING_TO_REPLACE" with "REPLACE_WITH" in file "index.html" and make a backup with suffix "bak"
sed -ibak -e s/STRING_TO_REPLACE/REPLACE_WITH/g index.html
find all gzip files in a folder
find /home/foo -name "*.gz"
As root, edit the cron job list of user "apache" using the editor specified by EDITOR environment variable, or default /usr/bin/editor if this variable is not set.
sudo crontab -e -u apache
Counts lines of all *.txt files in a current folder.
cat *.txt | wc -l
Find all files under and below /dir that were changed or created less than 60 minutes ago
find /dir -cmin -60
List all files under current directory with their paths and sizes
find . -type f |xargs ls -lS |head -20 | awk '{print $9, $5}'
Replace all instances of "STRING_TO_REPLACE" with "STRING_TO_REPLACE_IT" in "index.html" and write the output to standard output and "index.html"
sed s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g index.html | tee index.html
Find all files/directories which have been modified from the start of the day in directories/files taken from the glob pattern '/tmp/test/*'
find /tmp/test/* -daystart -mtime -0
Print a list of all regular files residing in the current directory
find . -maxdepth 1 -type f -print0
Find all files under current directory
find . -type f -print
search for a word in all c files in the current folder
find . -name '*.c' | xargs grep 'stdlib.h'
Delete all files that have not been accessed in the last 30 days
find . -type f -atime +30 -exec rm {} \;
search for the file "file" in the current folder excluding those in the sub directory ".git"
find . -path ./.git -prune -o -name file -print
Unsets shell functions 'ls' and '/bin/ls'.
unset -f ls /bin/ls
Create the directory '.npm-global' in the user's home directory.
mkdir ~/.npm-global
Find files and directories with group id 1003
find . -gid 1003
List all files under current directory that are greater than 10MB in size
find . -size +10M -exec ls -ld {} \;
Print the contents of all ".py" on the file system as input to "tqdm --unit loc --unit_scale True | wc -l"
find / -name '*.py' -exec cat \{} \; | tqdm --unit loc --unit_scale True | wc -l
display all the java, xml and action scripts files in a directory
find dir1 -type f -a \
Search for files/directories which are writable by both their owner and their group
find . -perm -220
Lists all files in a current folder, separating names with comma.
ls -1 | paste -sd "," -
Split "$SOURCE_FILE" into files of at most 100 lines each
split -l 100 "$SOURCE_FILE"
Prints +-10 lines around $LINENUM in filename
head -<$LINENUM + 10> filename | tail -20
Find files which are more than 2 days old under ${userdir}/${i}/incoming directory
find ${userdir}/${i}/incoming -mtime +2 -type f -ls
change the current working directory to /some/dir and display all normal/regular files
cd "/some/dir" && find . -type f
Save absolute path of "$path" that must exist along with all parents to variable "abspath"
abspath=$
Attempt to connect as root via ssh to host "IP" and copy /root/K to local machine, passing option "StrictHostKeyChecking=no" to the ssh backend - this will normally fail because ssh servers by default don't (and shouldn't) accept root logins.
scp -o StrictHostKeyChecking=no root@IP:/root/K
Use 'top' to monitor process 'a.out', printing information 100 times.
top -b -p `pidof a.out` -n 100
find all the directories in the current directory which dont have the execute permission.
find -type d ! -perm -111
Find all *.sql files in maximum 1 level down the current directory, process it with sed and then send the output to a mysql command
find -maxdepth 1 -name '*.sql' -print0 \; | xargs -0 sed -e 's/ , );/1,1);/g' | mysql -D ootp
Find all 777 permission files and use chmod command to set permissions to 644
find / -type f -perm 0777 -print -exec chmod 644 {} \;
Print 'huzzah' if /some/dir/ is empty
find /some/dir/ -maxdepth 0 -empty -exec echo "huzzah" \;
Search /etc for files modified within the last day
find /etc -type f -ctime -1
Find all regular files in the current directory tree whose names end with ".DS_Store" and delete them
find . -type f -name '*.DS_Store' -ls -delete
Split "file.txt" into files of at most 1 MiB in size with a numeric suffix and prefix "file"
split -b 1M -d file.txt file
Count number of lines in all files matching "*R1*.fastq.gz"
zcat *R1*.fastq.gz | wc -l
Recursively copy "/path/to/data/myappdata/*.txt" to "user@host:/remote/path/to/data/myappdata/"
rsync -rvv /path/to/data/myappdata/*.txt user@host:/remote/path/to/data/myappdata/
Find all files whose permission are 777
find / -type f -perm 777
find all regular/normal files in the folder "myfiles" which have read and write permission to the other users
find /myfiles -type f -perm -o+rw
list all the files in the file system excluding proc folder and excluding symbolic links which have write permission for the user
find / -path /proc -prune -o -perm -2 ! -type l -ls
Show all processes that have a tty in format "%p %r %y %x %c "
ps x -o "%p %r %y %x %c "
search for all the regular/normal files in the current folder which start with "my"
find . -name 'my*' -type f
Find files/directories modified within the last day under /etc
find /etc -type f -ctime -1
Runs `file' on every file in or below the current directory.
find . -type f -exec file '{}' \;
Prints number of days in a current month.
cal $ | awk 'NF {DAYS = $NF}; END {print DAYS}'
Remove files from the file system that are owned by nobody
find / -nouser -exec rm {} \;
Change directory to the parent of the real path of the current script
cd $(dirname $(readlink -f $0))
find all the files in the folder /home which are exactly of size 10MB
find /home -size 10M
Print variable "$module" in formatted columns with at most 80 characters per line
echo $modules | column -t | fold | column -t
Recursively copy /path/foo on host "prod" to local directory "/home/user/Desktop", connecting as ssh username corresponding to local username.
scp -r prod:/path/foo /home/user/Desktop
Find all PHP files under current directory that contain only one line
find -name *.php -print | xargs -L1 awk 'NR>1{exit} END{if(NR==1) print FILENAME}'
Print first word of lines unique for 'file1' file
grep -o '^\S\+' <
search for a word in all the shell scripts in the current folder and display the matched files.
find . -type f -name "*.sh" -exec grep -l landoflinux {} \;
Creates file by template 'aws-sync-XXXXX' in a current folder and stores file name in a 'dir' variable.
dir="$"
Search for the regex 'pattern_to_search' in all files under '/directory/containing/files' and show the matched lines as well as the file names
find /directory/containing/files -type f -exec grep -H 'pattern_to_search' {} +
find all python files in current folder and test if there is a makefile in all these fodlers where these are present
find . -name '*.py' -exec bash -c 'test -f $/Makefile' -- {} \; -print
Set permissions to 755 for every subdirectory of the current directory
find . -type d -mindepth 1 -print -exec chmod 755 {}/* \;
Print the last 10 commands in history
history | tail -10