nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
find all the files in the home folder which are empty
find ~ -empty
print number of jobs
n_jobs=`expr $`
Remove files from the home directory tree that were last accessed more than 100 days ago
find ~ -atime +100 -delete
Move all files/directories under current directory to ~/play
find . | xargs -I'{}' mv '{}' ~/play/
Find all the .mp3 files in the music folder and pass to the ls command, -print0 is required if any filenames contain whitespace
find ./music -name "*.mp3" -print0 | xargs -0 ls
Convert directory of files from dos to unix
find . -type f | while read file; do sed -e 's/^M//g' -i "$file"; done
Append the contents of "file.txt" to the current in-memory history list
history -r file.txt
search for files having python in filename
find / -name '*python*'
Search the current directory tree for symbolic links to files matching pattern '*/test*'
find -P . -lname '*/test*'
Get domain "$domain" IP address
dig +short "$domain"
Find all files/directories under '/usr/share/data' directory tree that match the posix extended regex ".*/20140624.*" in their paths and save the list to '/home/user/txt-files/data-as-of-20140624.txt'
find /usr/share/data -regextype posix-extended -regex ".*/20140624.*" -fprint /home/user/txt-files/data-as-of-20140624.txt
find all files in current folder which are bigger than 1 MB and move them to another folder
find . -size +1M -print0 | xargs -0 -I '{}' mv '{}' files
Find all regular files starting from level 3 of directory tree ~/container and move them one level up
find ~/container -mindepth 3 -type f -execdir mv "{}" $(dirname "{}")/.. \;
find files in /u/bill directory which are access an 2 to 6 minutes ago
find /u/bill -amin +2 -amin -6
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 {} \;
Search for 'string-to-find' in all files under current directory tree and show the matched lines with their filenames
find . -exec grep -H string-to-find {} \;
recursively change owner and group of the directory /opt/antoniod/ to user and group antoniod
chown -R antoniod:antoniod /opt/antoniod/
Delete all files/directories named 'FILE-TO-FIND' under current directory tree
find . -name "FILE-TO-FIND" -exec rm -rf {} \;
List all .gif files in the current directory tree
find . -name *.gif -exec ls {} \;
list all aliases
alias
Split "$1" into files of at most "$2" or default 10000 using a numeric suffix of length 6 and suffix "${tdir}/x"
split -l ${2:-10000} -d -a 6 "$1" "${tdir}/x"
Print info about thread number of process with pid 1
cat /proc/1/sched | head -n 1
Count the total number of lines in all HTML files under /usr/src that contain string "foo"
find /usr/src -name "*.html" -execdir /usr/bin/grep -H "foo" {} ';' | wc -l
Find and remove all .core files
find / -name "*.core" -print -exec rm {} \;
Print a detailed list of all regular files from the current directory tree
find . -type f -ls
Make directorie(s) 'es/LC_MESSAGES' as needed in the current directory
mkdir -p es/LC_MESSAGES
set alias "git-root" for command "if [ "`git rev-parse --show-cdup`" != "" ]; then cd `git rev-parse --show-cdup`; fi"
alias git-root='if [ "`git rev-parse --show-cdup`" != "" ]; then cd `git rev-parse --show-cdup`; fi'
Recursively bind "/sys" to "/var/snmp3/sys"
mount --rbind /sys /var/snmp3/sys
Copies 'src' to 'dest' preserving overwriting the existing files.
cp -n src dest
Count the number of unique duplicate lines in "file1" and "file2" combined
sort file1 file2 | uniq -d | wc -l
List all regular files matching the name pattern "$1*" under '/usr', '/bin', '/sbin' and '/opt' directory tree
find /usr /bin /sbin /opt -name "$1*" -type f -ls
Find files that are writable by the user, the group, or both under the current directory
find . -perm +220 -exec ls -l {} \; 2> /dev/null
List the files from the current directory tree that contain lines matching regular expression '^Subject:.*unique subject'
find . -type f -print0 | xargs -0 grep -il '^Subject:.*unique subject'
Print the current directory tree with file permissions
tree -p
Make directories to file "/full/path/to/file.txt" as needed
mkdir -p `dirname /full/path/to/file.txt`
Recursively finds string with text "foo" in all files of a current folder.
find ./ -type f | xargs grep "foo"
Find all files under path_to_dir
find path_to_dir -type f
display all files in current folder which are bigger than 1 MB
find . -size +1M
Remove regular files in the current directory tree
find . -type f -print0 | xargs -0 -n1 echo rm | sh -x
Find all files/directories named 'apt' in the entrie filesystem
find / -name "apt"
Search for 'pattern' in file 'file' and print the matched lines by separating them with spaces instead of newlines
grep pattern file | tr '\n' ' '
Execute command "$cmd_str" on host "$SERVER" as user "$USER"
ssh "$USER@$SERVER" "$cmd_str"
Remove containing directories from variable 'path' ie. "/some/specific/directory" becomes "directory".
path=$
Find all pdf files under /dir/containing/unsigned with null character as the delimiter
find /dir/containing/unsigned -name '*.pdf' -print0
find all the regular/normal files in the /path folder and delete them
find /path -type f -exec rm '{}' \;
Rename "new" to "old" and make a backup if "old" exists
mv new old -b
Saves path to the $SCRIPT file in the SCRIPTPATH variable.
set SCRIPTPATH=`dirname "$SCRIPT"`
delete all text files in the home folder after user confirmation
find $HOME/. -name "*.txt" -ok rm {} \;
search for all the text files in the folder /home/calvin/ and save the output to /tmp/search.log
find /home/calvin/ -name “*.txt” > /tmp/search.log
Combine every two lines of standard input
paste -d "" - -
Force create a symbolic link named "currentDir" to "newDir" without dereferencing "currentDir"
ln -sfn newDir currentDir
Print inode, permissions, size, and modification date of all files in the current directory tree as a list with an extra column prepended
tree -afispugD --inodes | awk '{FS="./"; ORS=""; printf("%-60s%s\n",$NF,$0)}'
Convert Unix `cal` output to latex table code.
cal | sed '1d;2{h;s/./ /g;x};/^\s*$/b;G;s/\n/ /;s/^...\.*/\1/;s/.../ &\t\&/g;s/\&$/\\\\/'
Counts all files in a current folder and in subfolders one-level lower, and sort folder list by number of files within.
find . -maxdepth 1 -type d -print0 | xargs -0 -I {} sh -c 'echo $ {}' | sort -n
Search all files in the current directory tree whose names end in "1" for string "1"
find . -name "*1" -exec grep "1" {} +
List files in the current directory and below except for GIT files
find . -not -iwholename '*/.git/*'
Find all files/directories under current directory tree whose paths match the pattern '*ACK*1'
find . -iwholename "*ACK*1"
Mount remote "smbfs" filesystem "//username@server/share" on "/users/username/smb/share" as soft
mount -t smbfs -o soft //username@server/share /users/username/smb/share
Print short DNS lookup for each domain name in a file 'list'
dig +short -f list
display all text files in the folder /tmp/1
find "/tmp/1" -iname "*.txt"
Print extended file information for regular files found under the home directory whose names start with my
find . -name 'my*' -type f -ls
Find all the files which are changed in last 1 hour in entire file system and show a few lines of output from the beginning
find / -cmin -60 | head
Remove all .mpg files in the /home/luser directory tree
find /home/luser -type f -name '*.mpg' -exec rm -f {} \;
Print all files in the current directory as a comma separated list
ls -1 | paste -sd "," -
Saves 'tmux' version in the 'tmux_version' variable.
tmux_version="$(tmux -V | cut -c 6-)"
Search the home directory tree for files matching pattern '*.txt'
find ~ -name *.txt
Print the lines of file "strings" specified in file "index"
join <(sort index) <(nl strings | sort -b)
Finds recursively all files in '/path/' excluding folders dir1, dir2 and all like *.dst, that contain 'pattern', and prints matched strings with string number and file name.
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
Search the current directory tree for *.wav files that have "export" in their pathnames
find -type f -name "*.wav" | grep export
Find all files under /mnt/naspath directory without descending into .snapshot directory that were modified in last 24 hours with null character as the delimiter
find /mnt/naspath -name .snapshot -prune -o \( -type f -mtime 0 -print0 \)
find all the jpg files in the current folder and resize them to 50% of their original size
find . -name "*.JPG" -exec convert {} -resize 50% {} \;
Find all image.pdf files/directories under ./polkadots
find ./polkadots -name 'image.pdf'
display all the text files in the temp folder
find /tmp -name *.txt
Find files and directories modified in last 24 hours
find . -mtime 1
search for the word "slrn" in all the files in the current folder
find ./ -exec grep -q 'slrn' '{}' \; -print
Set the 'pipefail' shell variable causing bash to return true only if all commands in a pipeline return true.
set -o pipefail
Copy "/path/to/source" to '/path/to/dest' in remote "username@computer"
rsync -r /path/to/source username@computer:/path/to/dest
Search the current directory tree for files containing "album" and "vacations" in their names and not containing "2015"
find . -name "*album*" -a -name "*vacations*" -a -not -name "*2015*"
ask user confirmation and delete all the files in the directory /mydir which have not been accessed in the last 100*24 hours
find /mydir -atime +100 -ok rm {} \;
See all pages in section 3.
apropos -s 3 .
Remove all regular files from the current directory tree whose names do not end with "ignore1" or "ignore2"
find . -type f -not -name '*ignore1' -not -name '*ignore2' | xargs rm
Find all files/directories named modules under current directory and list them twice
find . -name modules \! -exec sh -c 'find -name modules' \;
list all regular files under the directory "$directory"
find $directory -type f -name '*'
Recursively list contents of the current directory in a tree-like format
tree
prints the last occurrence of text between two tags
tac file | sed -n '0,/<tag>\(.*\)<\/tag>/s//\1/p'
create an archive using pbzip2 as a compress program
tar -I pbzip2 -cf OUTPUT_FILE.tar.bz2 paths_to_archive
remove top-level domain from URL's in urllist.txt
rev urllist.txt | cut -d. -f 2- | rev
Send an audible ping to "10.100.3.104"
ping -a 10.100.3.104
Print only group names from /etc/group.
cut -d: -f1 /etc/group
Save the directory name of the current bash script to variable "path" if it is found in one of the directories specified by PATH.
path="$( dirname "$" )"
Calculate the md5 sum of the contents of the sorted list of files "$FILES"
cat $ | md5sum
search for the file "process.txt" in the entire file system
find / -name "process.txt"
Search the files from the current directory tree for "chrome"
find . | xargs grep 'chrome'
Find all files/directories under current directory with null character as the delimiter
find . -print0
find all files that were modified between 90 to 100 days ago in home directory and delete then .
find /home -type f -mtime +90 -mtime -100 -exec rm {} \;
Find all *.php (case insensitive) files and *.js files/directories (case insensitive) under /home/jul/here excluding $EXCLUDE/* paths
find /home/jul/here -type f -iname "*.php" ! -path "$EXCLUDE/*" -o -iname "*.js" ! -path "$EXCLUDE/*"
Print the column count of compressed file "$file"
zcat "$file" | awk '{print NF}' | head
Change permissions to 0755 for all directories in the /path directory tree
find /path -type d -exec chmod 0755 {} \;
Lists all subdirectories in the current directory
ls -d -- */ ### more reliable GNU ls
Prints real path of the folder containing $0 file.
$(readlink -f $)