nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
List all files/folders in current directory by separating them with spaces
ls | tr "\n" " "
Remove all *.mp3 files in tmp directory but not in it's subdirectories
find tmp -maxdepth 1 -name '*.mp3' -maxdepth 1 | xargs rm
Find all files excluding *.gz files in the current directory tree and compress them with gzip
find . -type f ! -name '*.gz' -exec gzip "{}" \;
Decompress and extract 'libxml2-sources-2.7.7.tar.gz'
gzip -dc libxml2-sources-2.7.7.tar.gz | tar xvf -
Recursively remove all "*.txt" files and answer "y" to any prompt
yes | rm -r *.txt
Compress in parallel regular files in the current directory tree that were last modified more than 7 days ago
find . -type f -mtime +7 | tee compressedP.list | xargs -I{} -P10 compress {} &
print all lines after the last match of 'string match'
tac infile | sed '/string match/,$d' | tac
display all the files in the current folder
find .
Print the list of regular files from the current directory that were last modified on November, 22
find . -maxdepth 1 -type f -newermt "Nov 22" \! -newermt "Nov 23" -exec echo {} +
Find writable files in the current directory tree
find . -writable
Find all symbolic links under '/some/directory' driectory tree
find /some/directory -type l -print
Archive directory "/mnt/data" to "/media/WD_Disk_1/current_working_data/", deleting any extraneous files in destination, compress data during copy.
rsync -az --delete /mnt/data/ /media/WD_Disk_1/current_working_data/;
Recursively change the group of all files in "/var/lib/php/session" to "lighttpd"
chown -R :lighttpd /var/lib/php/session
find all the files in the file system which belong to the user "pat" and with the name "dateiname"
find / -user pat -iname "Dateiname"
Back up all *.txt files/directories in new files/directories with a .bak extension in their names under /etc directory
find /etc -print0 -name "*.txt" | xargs -I {} -0 mv {} {}.bak
Make all regular files in the current directory tree world-readable
find . -type f -print0 | xargs -0 chmod go+r
Find all *.htm files under current directory and print the changed names by appending 3 levels of parent directory names at the beginning and modifying the actual name to dd-nnn format
find -type f -name "*.htm" | sed 's@^./@@g;s@/@-@g' | awk -F'-' '{print $1 "-" $2 "-" $3 "-" substr($4, 5, 2) "-" $5}'
Overwirte file '/path/to/your/file' with zeroes and remove, showing progress while execution.
shred -v -n 0 -z -u /path/to/your/file #overwriting with zeroes and remove the file
Find all status.c files in the current directory tree and show stat's information on them
find . -name status.c -exec stat --format "%A %s %x %n" {} \;
Print the average round trip time of 5 pings to "google.com" from OSX
ping -c 5 google.com | grep "round-trip" | cut -f 5 -d "/"
Print linker search path using gcc formatted on new lines
gcc -print-search-dirs | sed '/^lib/b 1;d;:1;s,/[^/.][^/]*/\.\./,/,;t 1;s,:[^=]*=,:;,;s,;,; ,g' | tr \; \\012
find all the files in the home folder which are less than 42 Bytes
find / -size 42
Find directories modified within the last 7 days
find . -mtime -7 -type d
run command "createdb $DBNAME" as user postgres
su --login postgres --command "createdb $DBNAME"
search for text files in the current folder which have write access to others
find . -type f \( -iname "*.txt" -and -perm -o=w \)
Delimit standard input with ":" and display as a table
column -s: -t
Grab the output of "basename" (in this case "stuff") and echo it to stdout, which basename would do by default anyway.
echo $(basename /foo/bar/stuff)
find all the text files in current folder and change the extension of these files and move them to another folder
find . -name "*.txt" | parallel 'ext="{/}" ; mv -- {} foo/{/.}.bar.${ext##*.}'
Isolate first comma-delimited field of each line in "file", discard consecutive duplicates, and search "file" for first matching occurrence of that field.
cut -d, -f1 file | uniq | xargs -I{} grep -m 1 "{}" file
find all js files under the build direcotry except build/external directory.
find build -not \ -name \*.js
Rename "svnlog.py" to "svnlog"
mv svnlog.py svnlog
Display a binary file as a sequence of hex codes
od -t x1 file|cut -c8-
Finds real time report in a 'sleep 1' command execution statistic.
{ time sleep 1; } 2>&1 | grep real
delete all the broken symbolic links from the folder /usr/ports/packages
find -L /usr/ports/packages -type l -exec rm -- {} +
Gets MAC address of en0 network interface.
ifconfig en0 | grep -Eo ..\(\:..\){5}
List files greater than 1024KB under /path/to/directory and print the time and size on stdout
find /path/to/directory -type f -size +1024k -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'
Split "your_file" into files with at most 9 lines each
split -l9 your_file
Force create a symbolic link named "mylink" with target "/apps/myapps/new/link/target"
ln -f -s /apps/myapps/new/link/target mylink
Append the current user to the server access control list for X
xhost +si:localuser:`whoami`
Search the current directory tree for files whose name is ".note", case insensitive
find -type d -exec find {} -maxdepth 1 \! -type d -iname '.note' \;
search for the word "put" in all the files in the current folder which have the word "bills" in their name and display the matched line along with the filename.
find . -name '*bills*' -exec grep -H "put" {} \;
Search the directories matching pattern "/path/to/some/dir/*[0-9]" for level 1 subdirectories
find /path/to/some/dir/*[0-9] -type d -maxdepth 1
find all regular files then display the number of occurrences of banana without lines not proper end
find . -type f -print0| xargs -0 grep -c banana| grep -v ":0$"
display all text files in the current folder
find . -type f -name "*.txt"
find all hidden files in the current folder which have been modified after profile file
find . -type f -name ".*" -newer .cshrc -print
Read a line from standard input into variable "ENTERED_PASSWORD" without echoing the input
read -s ENTERED_PASSWORD
Find the largest 10 files (regular files) under current directory
find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
Saves exit statuses of piped commands in a system variable PIPESTATUS='
false | true
print bindings for "p" and "e" with no case sensitivity
bind -p|grep -i '"[pE]"'
search for php files in current directory and search for a word in all these files
find -name '*.php' -exec grep -iq "fincken" {} \; -exec grep -iq "TODO" {} \; -print
Find all ".gz" files in directory tree "files/" and use a count and the filename as arguments to "..."
find files/ -name "*.gz" | nl -n rz | sed -e 's/\t/\n/' | xargs --max-args 2 ...
Create a symbolic link named "$SYMLINK" to "$ACTUAL_DIR"
ln -s "$ACTUAL_DIR" "$SYMLINK"
Calculate the md5 checksum of the current directory structure and save it in variable SUM
SUM=$
Print file extension assuming there is only one dot in the file name.
echo "$FILE" | cut -d'.' -f2
find all the foo.txt files in the current folder and move them to another directory
find . -name "foo.txt" | awk '{ print "mv "$0" ~/bar/" | "sh" }'
Find all empty folders in the current directory and below
find . -type d -empty
Find symbolic links in /usr/lib and /usr/lib64 to files whose pathnames contain "libstdc++"
find /usr/lib/ /usr/lib64/ -lname "*libstdc++*"
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name vmware-*.log | xargs rm
Find all files named 'file' in 1 level down the current directory whose status were changed more than 1 hour ago
find . -maxdepth 1 -cmin +60 -name file
Search "inputfile" for lines starting with "t:" and group the results in files with at most 200 lines each
cat inputfile | grep "^t\:" | split -l 200
Find all files/directories under /var/www/some/subset and change their owner and group to www-data
sudo find /var/www/some/subset -print0 | xargs -0 chown www-data:www-data
Finds recursively all files having extension .c, .h in '/path/' that contain 'pattern', and prints matched strings with string number and file name.
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
delete all the empty file in the file system after user confirmation
find / -size 0 -ok rm { } \;
Find all regular files residing in the current directory tree and search them for string "/bin/ksh"
find . -type f -print | xargs grep -i 'bin/ksh'
Count number of A records of domain '$domain' on nameserver '$server' and save value in 'result' variable
result="$(dig +short @"$server" "$domain" | wc -l)"
Find all files/directories under current directory that were accessed less than 1 day ago
find . -atime -1 -print
search for the word "foo" in all the regular/normal files with the name "file-pattern" in the directory "/path/to/dir"
find /path/to/dir/ -type f -name "file-pattern" -print0 | xargs -I {} -0 grep -l "foo" "{}"
Print the contents of "n"
cat n
Find all *blue* files/directories under /myfiles
find /myfiles -name '*blue*'
Find all files under current directory matching the posix-egrep type regex '^.*/[a-z][^/]*$' in their names with locale set to default C locale
LC_ALL=C find . -regextype posix-egrep -regex '^.*/[a-z][^/]*$' -type f
Find all *.txt files/directories under current directory and execute process once with all of them as arguments
find . -name \*.txt -exec process {} +
find all the html files which are modified in the last 7 days
find . -mtime -7 -name "*.html"
Gets list of IP addresses of all network interfaces.
ifconfig | sed -En 's/127.0.0.1//;s/.*inet ?({3}[0-9]*).*/\2/p'
Print appended data in "/var/log/syslog" as the file grows
tail -f /var/log/syslog
find files in home directory that accessed more than 100 days ago
find ~ -atime 100
Print all unique directory paths under "dir1" compared to "dir2"
comm -23 <(find dir1 -type d | sed 's/dir1/\//'| sort) <(find dir2 -type d | sed 's/dir2/\//'| sort) | sed 's/^\//dir1/'
Find and the 5 largest regular files in the Downloads folder of tecmint's home directory and output the file sizes in bytes.
find /home/tecmint/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5
Search for all files with same inode NUM
find . -inum NUM
display all the directories in the folder /var and do not go beyond 2 levels during search
find /var -maxdepth 2 -type d;
Print a sorted list of all .jpg files in the current directory and below
find -name '*.jpg' | sort -n
Save full path of command "tr" to variable "TR"
TR=`which tr`
find all files in the entire file system whose size is more than 100MB
find / -size +100M
Recursively copies all files in the current directory but ones that names match pattern "dirToExclude|targetDir" to the 'targetDir' directory, printing info message on each operation.
cp -rv `ls -A | grep -vE "dirToExclude|targetDir"` targetDir
Print '"HTTP/1.1 200 OK', two new lines and the current date
echo -e "HTTP/1.1 200 OK\n\n $"
Prints process tree of a current process with id numbers and parent processes.
pstree -sp $$
run bash in screen and source a file before printing the prompt
screen bash --rcfile yourfile.rc
Display a long listing of all the regular files under current directory tree that are newer than ‘Apr 18 23:59:59 EDT 2013’ and older than ‘Apr 20 00:00:00 EDT 2013’ by modification time
find . -type f -newermt ‘Apr 18 23:59:59 EDT 2013’ ! -newermt ‘Apr 20 00:00:00 EDT 2013’ -exec ls -l ‘{}’ \;
Count the number of users logged in minus one
who | sed 1d | wc -l
compresses all the files in the current folder with default depth
find . -depth -print | cpio -dump /backup
Search the system for directories named "needle"
find / -type d -name "needle"
Executes tmux commands that are stored in the '$tmux_command' variable, and then attaches to the tmux session.
tmux "$tmux_command \; attach"
Save the contents of "numbers.txt" to variable "f"
f=$
Search the current directory and all subdirectories for files that have 777 permissions and the permissions to 755
find . -type f -perm 777 -exec chmod 755 {} \;
Repeat "image.png" 10 times on a single line
echo $
Removes empty folder, and hides error message if one is not empty.
rmdir --ignore-fail-on-non-empty $newBaseDir/Data/NewDataCopy
Processes all files recursively in /var/spool/cron/tabs folder and filters out all strings with '#'.
grep -v "#" -R /var/spool/cron/tabs
create a symbolic link named "test" to file ".bashrc"
ln -s .bashrc test
Find all the files in entire file system which are accessed 50 days back
find / -atime 50
Find files with group write permission and remove the permission
find . -perm -20 -print | xargs chmod g-w
Find all the SGID bit files whose permissions set to 644
find / -perm 2644