nl
stringlengths
13
387
bash
stringlengths
1
532
Rename "www_new" to "www" even if "www" directory exists
mv -T www_new www
Rename $file file, preserving only part of name before '-' symbol, and appending '.pkg' suffix to the end
mv $file $(echo $file | rev | cut -f2- -d- | rev).pkg
Rename '.mkv' extension to '.avi' for all files/directories under '/volume1/uploads' directory tree
find /volume1/uploads -name "*.mkv" -exec rename 's/\.mkv$/.avi/' \{\} \;
Rename the *.so files at level 2 of the current directory tree prepending their names with "lib"
find . -mindepth 2 -maxdepth 2 -name "*.so" -printf "mv '%h/%f' '%h/lib%f'\n" | sh
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" | bash
Rename absolute path of symbolic link "dirln" to "dir2"
mv "$(readlink -f dirln)" dir2
renames all ".htm" files to ".html" files
find . -name "*.htm" -exec mv '{}' '{}l' \;
Rename all "thumbs" directories to "thumb" in the current directory tree
find . -type d -exec rename 's/^thumbs$/thumb/' {} ";"
Rename all *.html files under and below the current directory to *.var
find -name '*.html' -print0 | xargs -0 rename 's/\.html$/.var/'
Rename all *.txt regular files in the current directory tree to *.abc
find . -type f -iname '*.txt' -print0 | xargs -0 rename .txt .abc
Rename all .jpg files to .jpeg under the current directory and below
find | rename 's/\.jpg$/.jpeg/'
Rename all .png files, changing the string "_h.png" into "_half.png".
rename 's/_h.png/_half.png/' *.png
Rename all files in current directory to lowerase.
rename 'y/A-Z/a-z/' *
Rename all files in current directory to lowerase, overwriting any existing files.
rename -f 'y/A-Z/a-z/' *
Rename all files in current directory whose name starts with 'F0000', trimming a zero from any sequence of four zeroes in the name.
rename s/0000/000/ F0000*
Rename all files in current directory with names starting with "fgh" so they start with "jkl" instead
rename 's/^fgh/jkl/' fgh*
Rename all files matching "access.log.<number>.gz" incrementing <number>.
find -name 'access.log.*.gz' | sort -Vr | rename 's/(\d+)/$1+1/ge'
Rename all regular files under current directory tree with inode number 31467125 to 'new_name.html'
find . -type f -inum 31467125 -exec mv {} new_name.html \;
rename all the text files in the current folder to html files
find -name "*.txt" -exec mv {} `basename {} .htm`.html \;
Rename file "edited_blah.tmp" to "/etc/blah"
sudo mv edited_blah.tmp /etc/blah
Rename file file.txt.123456 to file.txt
mv file.txt.123456 $(ls file.txt.123456 | rev | cut -c8- | rev)
Rename file with inode number 31467125 to new_name.html
find . -type f -inum 31467125 -exec /bin/mv {} new_name.html \;
Rename file ~/junk/cart1 to ~/junk/A
find ~/junk -name 'cart1' -exec mv {} ~/junk/A \;
Rename recursively all files in the current directory tree that are called "article.xml" to "001_article.xml"
find . -name "article.xml" -exec rename 's/article/001_article/;' '{}' \;
Rename uppercase file or folder name $1 to lower case name
mv $1 `echo $1 | tr '[:upper:]' '[:lower:]'`
Replace the "openssl" command executable with a symbolic link to "/usr/local/ssl/bin/openssl"
sudo ln -sf /usr/local/ssl/bin/openssl `which openssl`
Replace all ' ' with '-' from standard input
tr ' ' '-'
Replace all colons (':') with newlines in $list and search for the first match to the regex "^$removepat\$" where $removepat is a variable and save the result to variable 'removestr'
removestr=$(echo "$list" | tr ":" "\n" | grep -m 1 "^$removepat\$")
Replace all non-punctuation characters with newlines from standard input
tr -sc '[:punct:]' '\n'
Replace all spaces (' ') with comma (',') in ${TO_IGNORE[@]}, append with '--ignore ' and save the resultant string to variable 'ARGS'
ARGS="--ignore `echo ${TO_IGNORE[@]} | tr ' ' ','`"
Replace all spaces with underscores in directory names under current directory.
find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
Replace all spaces with underscores in directory paths under current directory.
find -name "* *" -type d | rename 's/ /_/g'
Replace all spaces with underscores in file paths under current directory.
find -name "* *" -type f | rename 's/ /_/g'
Replace any blank character from standard input with a tab
tr '[:blank:]' \\t
Replaces any occurences of '*favicon.ico*' in any subfolder with file '/root/favicon.ico'.
find . | grep favicon\.ico | xargs -n 1 cp -f /root/favicon.ico
Replace any sequence of spaces in file 'text.txt' with single space and print 4th space separated field
cat text.txt | tr -s ' ' | cut -d ' ' -f 4
Replace commas (',') with newlines in $MOUNT_OPTS and search for the regex '^acl$'
echo $MOUNT_OPTS | tr , \\\n | grep '^acl$' -q
Replace each new line in "INPUT.txt" with ":"
paste -sd: INPUT.txt
Replace each newline in input "1\n2\n3\n4\n5" with a comma
echo "1\n2\n3\n4\n5" | paste -s -d, /dev/stdin
Replace newline with "_" in "file" then search for "_foo_" and output with "_" characters deleted
grep -o "_foo_" <(paste -sd_ file) | tr -d '_'
Replace spaces in directory names with underscores for all directories in the current directory tree
find -name "* *" -type d | rename 's/ /_/g'
Replace spaces in file names with underscores for all files in the current directory tree
find -name "* *" -type f | rename 's/ /_/g'
Replace spaces with underscores in the names of all files and directories in the "/tmp" directory tree
find /tmp/ -depth -name "* *" -execdir rename " " "_" "{}" ";"
Replace spaces with underscores in the names of all files and directories in the "/tmp" directory tree
find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;
Report all C language source code files under the current directory
find . -name \*.c -print
Report all files in /mydir1 and /mydir2 larger than 2000 blocks and accessed in over 30 days
find /mydir1 /mydir2 -size +2000 -atime +30 -print
Report all files starting in the directories /mydir1 and /mydir2 larger than 2,000 blocks that have not been accessed in over 30 days
find /mydir1 /mydir2 -size +2000 -atime +30 -print
Report available space on the file system containing /tmp in kilobytes.
df -k /tmp | tail -1 | tr -s ' ' | cut -d' ' -f4
Reports count of characters in the value of ${FOO_NO_EXTERNAL_SPACE} variable as follows: "length(FOO_NO_EXTERNAL_SPACE)==<counted number of characters>"
echo -e "length(FOO_NO_EXTERNAL_SPACE)==$(echo -ne "${FOO_NO_EXTERNAL_SPACE}" | wc -m)"
Reports count of characters in the value of ${FOO_NO_TRAIL_SPACE} variable as follows: "length(FOO_NO_TRAIL_SPACE)==<counted number of characters>"
echo -e "length(FOO_NO_TRAIL_SPACE)==$(echo -ne "${FOO_NO_TRAIL_SPACE}" | wc -m)"
Reports count of characters in the value of ${FOO_NO_WHITESPACE} variable as follows: "length(FOO_NO_WHITESPACE)==<counted number of characters>"
echo -e "length(FOO_NO_WHITESPACE)==$(echo -ne "${FOO_NO_WHITESPACE}" | wc -m)"
Reports count of processors in system.
grep "^core id" /proc/cpuinfo | sort -u | wc -l
Reports count of processors in system.
grep '^core id' /proc/cpuinfo |sort -u|wc -l
Report file system '/dev/disk0s2' disk usage
df | grep /dev/disk0s2
Report file system containing /example disk usage in kilobytes.
df -k /example
Report file system containing /tmp disk usage in kilobytes.
df -k /tmp
Report file system containing the current directory disk usage
df .
Report file system containing the current directory disk usage in kilobytes.
df -k .
Report file system containing path to /dir/inner_dir/ disk usage human-readable.
df -h /dir/inner_dir/
Report file system containing path to /dir/inner_dir/ disk usage in kilobytes.
df -k /dir/inner_dir/
Report file system containing path to /some/dir disk usage in kilobytes.
df -k /some/dir
Report file system containing path to the current working directory disk usage human-readable.
df -h .
Report file system containing path to the current working directory inodes usage.
df -i $PWD
Report file system disk space usage in human readable format
df -h
Report file systems disk usage human-readable using POSIX output format.
df -Ph
Report file systems disk usage in 1GB blocks.
df -BG
Report file systems disk usage in kilobytes.
df -k
Report file systems disk usage using POSIX output format.
df -P
Report file systems inode usage.
df -i
Report file systems inodes usage.
df -i
Report file system inodes usage in human readable format
df -ih
Report file system mounted at $path_in_question disk usage if canonical path $path_in_question is a mount point.
df $path_in_question | grep " $path_in_question$"
Report total disk usage info on root file system, printing all sizes as power of 1000
df -H --total /
Report total file systems disk usage.
df --total | tail -n 1
Report total file systems disk usage estimated in terabytes
df --total -BT | tail -n 1
Report total file systems disk usage in 1T blocks.
df --total -BT | tail -n 1
Represent current date in RFC 3339 format with precision to seconds and save it to 'timestamp' variable
timestamp=`date --rfc-3339=seconds`
Represent the current time as seconds since epoch and save it to variable 'TODAY'
TODAY=$(date -d "$(date +%F)" +%s)
Represent time string $MOD_DATE as seconds since epoch and save to variable 'MOD_DATE1'
MOD_DATE1=$(date -d "$MOD_DATE" +%s)
Represent the UTC date given in time string "1970.01.01-$string1" as number of seconds since the epoch and save it in 't1' variable
t1=$(date -u -d "1970.01.01-$string1" +"%s")
Request A record from nameserver $ns for domain name $d, filter strings with domain name and exclude lines matching 'DIG'
dig @$ns $d A | grep $d | grep -v "DiG"
Request changing the passphrase of key file "private.key"
ssh-keygen -pf private.key
Request IP address for each domain name received on the command input
dig +short -f - | uniq
Request IP address of 'myip.opendns.com' from name server 'resolver1.opendns.com'
dig +short myip.opendns.com @resolver1.opendns.com
Request MX record of 'example.com' domain, and filter out all comment strings
dig mx example.com | grep -v '^;' | grep example.com
Request NS record for com. domain, receiving only authoritative answers
dig NS +aaonly com.
Request that the master ssh connection "officefirewall" exits
ssh -O exit officefirewall
Request that the master ssh connection "otherHosttunnel" exits
ssh -O exit otherHosttunnel
Resolve all symlinks in path to "firefox" binary if it exists in path, resulting in absolute path with no symlinks.
readlink -f $(which firefox)
Resolve any symlinks in working directory, and go to resulting pathname.
cd "`pwd -P`"
Resolve symbolic link of file "/foo/bar/baz"
readlink -e /foo/bar/baz
Resolve symbolic link of file "FILE" even if the file does not exist
readlink -m FILE
Resolve symbolic link of path of "python2.7"
readlink $(which python2.7)
Return 0 if at least one "abc" file in the current directory tree contains text "xyz"
find . -name 'abc' -type f -exec grep -q xyz {} +
returns a list of files create time is 1 minute ago under the root directory.
find / -newerct '1 minute ago' -print
returns a list of files modification newer than poop
find . -mnewer poop
Return a list of files newer than file poop
find . -mnewer poop
Return all of the .conf files in Pat's user folder and subdirectories
find /home/pat -iname "*.conf"
Return the depth of the current directory tree
find . -type d -printf '%d:%p\n' | sort -n | tail -1
Return the files that are newer than file `myfile'
find / -newer myfile