nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
extract 'archive.tar.gz' to /destination
tar xzf archive.tar.gz -C /destination
Find all files that have wrong permission
find / \( -perm -006 -o -perm -007 \) \( ! -type -l \) -ls
Split "hugefile.txt" into files with 100000 lines each starting with "part." and using numeric suffixes
split -a4 -d -l100000 hugefile.txt part.
display all the regular files in the current folder that are less than 10KB
find . -type f -size -10k
display all the regular/normal files ending with ".mod" in a folder
find "$dir" -name "*.mod" -type f -print0
find files ending with .jpg
find . -name '*.jpg' -print ./bar/foo.jpg
Strips two last sections from the path $pathname, and prints basename of the rest part.
echo $(basename $(dirname $))
Compress from standard input and print the byte count preceded with 'gzip.'
echo gzip. $
List all environment variables (name and value) whose name either equals PATH or starts with GOBIN
env | grep '^\(GOBIN\|PATH=\)'
Run a "rm" process to recursively remove "cache", making it immune to all SIGHUP signals sent to it.
nohup rm -rf cache &
find all js files which path does not contain ./node_modules/* nor './vendor/*"
find -name '*.js' -not -path './node_modules/*' -not -path './vendor/*'
find a difference between website content of "http://tldp.org/LDP/abs/html/" and "http://www.redhat.com/mirrors/LDP/LDP/abs/html/"
diff < <
delete all the "wmv" "wma" files in the currnet folder,
find . \ -exec rm {} \;
Search the current directory tree for .log files containing the string "The SAS System", and save their names to sas_log_list.txt
find . -name "*.log" -exec grep -l "The SAS System" {} \; > sas_log_list.txt
Recursively changes group ownership of everything in a '/home/user1/project/dev' folder to 'project_dev'.
chgrp -R project_dev /home/user1/project/dev
change the owner and group of all the normal/regular files in the current folder and /home/admin/data/ to admin & admin
find . /home/admin/data/ -type f -exec chown admin.admin {} \;
Finds only parts of echoed string that match with regex 'run-parts (-{1,2}\S+ )*\S+', and saves them in $match variable, each matched part on a separate line.
match=$(echo "${line}" | egrep -o 'run-parts (-{1,2}\S+ )*\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 {} \;
Split "data.tsv" into files of at most 5000000 lines each with prefix "_tmp"
split -l5000000 data.tsv '_tmp';
Generates a randomly sorted list of numbers from 1 to 10.
seq 1 10 | sort -R | tee /tmp/lst |cat <(cat /tmp/lst) <(echo '-------') \ <(tac)
display all normal / regular files in current folder in reverse order
find . -type f | tac
Prints elapsed time of command execution.
\time -f%e sleep 1
Remove with prompting all files starting in /mydir that have not been accessed in over 100 days
find /mydir -atime +100 -ok rm {} \;
Displays information about all network interfaces in system, including inactive ones.
ifconfig -a
For each line whose second field is the same in both files, output: first field of second file, second field of first file, and first field of second file.
join -j 2 -o 1.1 1.2 2.1 < <
find the file with the name "file" in the entire file system
find / -name file
Find *.java files in the current directory with GNU find and replace foo with bar in those files
find . -name "*.java" -exec sed -i s/foo/bar/g \;
Print absolute path of "PATH"
readlink -f PATH
Find all symbolic links starting from the current directory and list them
find . -type l -ls
Execute the 'echo' command on each file from the current directory tree individually
find . -exec echo {} \;
Print the base name via grep of the current working directory
pwd | grep -o '[^/]*$'
Find regular files in the current directory tree that have the user executable bit set
find . -type f -perm -u=x
ssh into localhost on port 4444
ssh -p 4444 localhost
Concatenate files containing `test' in their names
find . -name '*test*' -exec cat {} \;
Write the output of "proc1" to standard output and to all commands from "proc2" to "procN"
proc1 | tee > ... > | procN
Recursively findsfiles with text pattern in current folder, ingnoring case differences, prefixes each matched line with number in file and suppresses error messages about nonexistent or unreadable files.
grep -insr "pattern" *
display all non empty directories in current folder
find . \! -empty -type d
Find all files/directories that have read, write, execution permission for user and belong to the user 'my_user' under current directory tree
find . -user my_user -perm -u+rwx
Attempt to connect as root via ssh to host whose IP address or hostname is specified by environment variable IPADDRESS - this will normally fail because ssh servers normally don't accept root logins.
scp -rp "DAILY_TEST_FOLDER" "root@${IPADDRESS}:/home/root/"
List each unique character in "file" prefixed by number of occurrences and sorted from most frequent to least frequent
grep -o . filename | sort | uniq -c | sort -nr
Delete all hard links to the physical file with inode number 2655341
find /home -xdev -inum 2655341 | xargs rm
This will remove all files modified longer than 14 days ago under /root/Maildir/ recursively from there and deeper (mindepth 1
find /root/Maildir/ -mindepth 1 -type f -mtime +14 | xargs rm
Search the .py files residing in the current directory tree for "something" and save the output to output.txt
find . -name '*.py' -exec grep 'something' {} \; > output.txt
List existing screen sessions
screen -ls
Print the sizes and file names of all files in the current directory tree that are between 700k and 1000k
find . \ -exec du -Hs {} \; 2>/dev/null
split compressed content of the directory /home into pieces per 4000 mb named as "/media/DRIVENAME/BACKUPNAME.tgz.NNN"
tar --one-file-system -czv /home | split -b 4000m - /media/DRIVENAME/BACKUPNAME.tgz
Sources script incl.sh in the folder where current script is located.
source $/incl.sh
Archive all non-hidden files in the current directory and its sub-directories in the file arch.cpio
find ./* | cpio -o > arch.cpio
Find all files under current directory matching the regex '.*\(\(error\|access\)\(_log\)?\|mod_jk\.log\)\.[0-9]+' in their paths
find -type f -regex '.*\(\(error\|access\)\(_log\)?\|mod_jk\.log\)\.[0-9]+'
Search /tmp/ for files smaller than 100 bytes
find /tmp -size -100c
display a long listing of all the normal/regular files in the current folder (print0 is used to handle files which have newlines in their names or files with the name only as spaces )
find . -type f -print0 | xargs -0 ls -l
Search the current directory tree for all files matching pattern "*.rb"
find . -name "*.rb"
create directory /etc/cron.15sec
mkdir /etc/cron.15sec
Recursively change the owner and group of "subdir3" to "user3"
chown user3:user3 -R subdir3
Print reverse lookup for adress 127.0.0.1
dig -x 127.0.0.1
Print the current directory
find -prune
Find all files under /home/username/public_html/sites/all/modules and set their permission to 640
find /home/username/public_html/sites/all/modules -type f -exec chmod 640 {} +
Print numbers 1 through 10 separated by ":"
yes | head -n10 | grep -n . | cut -d: -f1 | paste -sd:
Find all *.jpg files under current directory
find . -iname '*.jpg'
search for all the files in current folder which start with "file2015-0" and move them to frst 400 fiiles to another folder
find . -name "file2015-0*" | head -400 | xargs -I filename mv filename
Print the MD5 message digest of "/path/to/destination/file"
md5sum /path/to/destination/file
Find all .php files in all directory trees matching pattern `/srv/www/*/htdocs/system/application/' and search those files for string "debug ("
find /srv/www/*/htdocs/system/application/ -name "*.php" -print0 | xargs -0 grep -H "debug ("
Copy all files matching "file_name.extension" to "/path/to/receiving/folder" preserving directory hierarchy
find . -name 'file_name.extension' -print | cpio -pavd /path/to/receiving/folder
display all the files in the current folder which have are bigger than 1KB
find . -size +1024 -print
Find all files/directories named 'photo.jpg' (case insensitive) under current directory tree
find . -iname "photo.jpg"
Find all the Sticky Bit set files whose permission are 551
find / -perm 1551
Find "*.dat" files recursively in the current directory, print the lines starting on line 5 to the console and save to "concat.txt"
find . -type f \ -exec tail -n+5 -q "$file" {} + |tee concat.txt
Read a line from standard input with a timeout of 0.1 seconds and prompt "This will be sent to stderr"
read -t 0.1 -p "This will be sent to stderr"
display all the files in the entire file system
find / -type f -exec echo {} \;
Print the compressed size, uncompressed size, compression ratio, and uncompressed filename of "file.zip"
gunzip -l file.zip
Find the largest files in a particular location
find /home/tecmint/Downloads/ -type f -exec du -Sh {} + | sort -rh | head -n 5
Recursively prints paths to all text file in folder .
grep -RIl "" .
Check whether current terminal is opened in a screen session.
pstree --show-parents -p $$ | head -n 1 | sed 's/\+.*/\1/' | grep screen | wc -l
List any line in "f1" or "f2" which does not appear in the other and delete all tab characters in the output
comm -3 < < | tr -d '\t'
Find files with the extension .conf in the /etc directory
find /etc -name '*.conf'
find all the directories starting with the name "someNamePrefix" which have not been modified in the last 10 days and force delete them
find /somePath -type d -name ‘someNamePrefix*’ -mtime +10 -print | xargs rm -rf ;
Search for files/directories with the case insensitive pattern anaconda.* in /var/log
find /var/log/ -iname anaconda.*
Print details for all files in the ./work directory tree with extension .sh that were modified less than 20 days ago
find ./work/ -type f -name "*.sh" -mtime -20 | xargs -r ls -l
Find files with 002 permission under /tmp and print them with the string 'Found world write permissions:' printed as the first line of output or print 'No world writable found' if no such files were found
find /tmp -type f -perm -002 | awk -- '1{print "Found world write permissions:";print};END{if(NR==0)print "No world writable found."}'
find files which full path name is /tmpfoo/bar under foo directory and print
find foo -path /tmp/foo/bar -print
create directory certs
mkdir certs/
Find recursively all regular files in the current directory tree ending in .dll or .exe
find . -type f | grep -P "\.dll$|\.exe$"
display all files in the directory "dir" which have been accessed in the last 60 minutes
find /dir -amin -60
Remove trailing white spaces from all files under current directory ignoring *.jpg, *.png and *.ttf files
find . -not \ --type f -print0 | xargs -0 sed -i '' -E "s/[[:blank:]]+$//"
Find all text files in the home directory
find ~/ -name '*.txt'
display all the files in the current folder excluding those that are present in the path "./etc"
find . ! -wholename "./etc*"
search for all the text files and display the long listing of these files from that directory
find . -name "*.txt" -execdir ls -la {} ";"
Find all files in current directory and search for 'searchName' in those files and show errors for files that are not directly on the current directory
find ./ -name "*" -printf "%f\n" | xargs grep "searchName"
create an archive using pbzip2 as a compress program
tar -I pbzip2 -cf OUTPUT_FILE.tar.bz2 /DIR_TO_ZIP/
Go to directory /some/where/long
cd /some/where/long
Pass a wildcard to scp by escaping it: copy all files with names starting with "files" in directory "/location" on host "server" to current directory on local machine, displaying debug info and preserving timestamps and permissions on copied files.
scp -vp me@server:/location/files\*
Saves printed calendar for $month, $year in positional variables.
set `cal $month $year`
Find '*prefs copy' files under /mnt/zip and delete them with confirmation prompt
find /mnt/zip -name "*prefs copy" -print0 | xargs> -p rm
Find all files in current directory excluding hidden files, archive them and put the output into variable full_backup_dir
full_backup_dir="$(find . -depth \( -wholename \./\.\* \) -prune -o -print | cpio -oav)"
Move all directories in the current directory tree that have been modified in the last day to "/path/to/target-dir"
find . -depth -type d -mtime 0 -exec mv -t /path/to/target-dir {} +
create a tar of all png & jpg images in the current folder
find . \ -print -exec tar -rf images.tar {} \;
run "your_command", letting the user page through the output and move around with the arrow keys - the Q key terminates and returns to the shell prompt.
"your_command" | less
Find an inode and remove
find . -inum 968746 -exec rm -i {} \;
Find all files/directories named file1 under current directory
find -name file1
find regular/normal files in the current folder
find -type f