nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Creates temporary file with file name formatted like /tmp/gnuplot_cmd_$(basename "${0}").XXXXXX.gnuplot and saves path to it in a variable 'gnuplotscript'.
gnuplotscript=$(mktemp /tmp/gnuplot_cmd_$(basename "${0}").XXXXXX.gnuplot)
find all the files in the current folder with the name "test-a" and move them to the folder test-10. execdir runs the command in the directory where the file is found.
find ~ -type f -name test-a -execdir mv {} test-10 \;
Find all MP3 files in the home directory tree that were modified in the last 24 hours
find ~ -type f -mtime 0 -iname '*.mp3'
Search for "facebook\|xing\|linkedin\|googleplus" in "access-log.txt" and print a count of the unique entries
grep -ioh "facebook\|xing\|linkedin\|googleplus" access-log.txt | sort | uniq -c | sort -n
Delete all .svn subdirectories under current directory
rm -rf `find . -type d -name ".svn"`
Find all files/directories under current directory that were accessed more than 25 but less than 35 minutes ago
find -amin +25 -amin -35
Set variable "extract_dir" to list of top-level directories and files contained in tar archive specified by variable FILE.
extract_dir=$(tar -tf $FILE | cut -d/ -f1 | uniq)
find all the files that are modified in the last 1 day
find -mtime -1
Finds files in 'directory' folder with the same name and location but different content than files in 'directory.original' folder and prints location of such files.
diff -qr directory directory.original | cut -d' ' -f2 | xargs dirname | uniq
find all the empty directories in current folder and delete them
find ./ -empty -type d -delete
Save $line line in history
history -s "$line"
Measure the disk space taken up by all *.txt files in the current directory tree
find . -name "*.txt" -print0 |xargs -0 du -ch
Output all lines in BigFile.csv whose secondn comma-separated second field matches first field of a line in LittleFile.csv.
join -1 2 -2 1 -t, BigFile.csv LittleFile.csv
Recursively change the owner and group of "/var/antoniod-data/" to "antoniod"
chown -R antoniod:antoniod /var/antoniod-data/
List each unique case insensitive character in "file" prefixed by number of occurrences
grep -o . file | sort -f | uniq -ic
Removes files ~/.android/adbkey and ~/.android/adbkey.pub without prompting.
rm -f ~/.android/adbkey ~/.android/adbkey.pub
Places current job to background.
bg % so it wont die when you logoff
Recursively find the latest modified file in the current directory
find . -type f | xargs ls -ltr | tail -n 1
display a long listing of all the regular/normal files in the file system which have set uid bit or set gid bit enabled.
find / -type f \ -exec ls -l {} \;
Prints process tree with command line arguments and process id numbers.
pstree -apl
display only the file names of all the files which end with ".deb"
find . -name '*.deb' -printf "%f\n"
Display a long listing of all regular files that are less than 50 bytes in size under '/usr/bin' directory tree
find /usr/bin -type f -size -50c -exec ls -l '{}' ';'
Archive all files specified on standard input under "/path/to/files" to "/path" on host "targethost" as user "user" with escalated privileges
rsync -av --files-from=- --rsync-path="sudo rsync" /path/to/files user@targethost:/path
Finds out what groups a given user has.
groups user
Creates temporary folder relative to directory '/path/to/dir'.
mktemp -d -p /path/to/dir
Find files newer than start.txt but not newer than end.txt
find ./ -newer start.txt -and ! -newer end.txt
find all jpg files in the current folder
find . -name "*.jpg"
Change string "searc" to "replace" in all files in directory hierarchy
find . -type f -exec sed -i 's/searc/replace/g' {} \;
Execute "dropbox-cli status" every second
watch -n1 dropbox-cli status
Read a line from standard input into variable "response" ignoring backslash escapes and using the prompt "Are you sure? [y/N] "
read -r -p "Are you sure? [y/N] " response
List regular files in current directory with read, write and execute permission for all users and also show the permissions
find . -type f -perm a=rwx -exec ls -l {} \;
find from / a file called "expect", suppressing any error messages
find / -name expect 2>/dev/null
list in long format all files from / whose filename ends in "jbd", not descending into directories that are not readable while searching, and not descending into directories on other filesystems
find / -mount \! -readable -prune -o -path /dev -prune -o -name '*.jbd' -ls
Display a dump of "file" as floating point values of double size
od -t fD file
display all empty files in the current folder
find . -size 0k
Get only the latest version of the file 'filename' under current directory
find . -name 'filename' | xargs -r ls -tc | head -n1
Copy all ".php" files in "projects/" directory tree to "copy/" preserving directory hierarchy
find projects/ -name '*.php' -print | cpio -pdm copy/
Remove files whose names match regular expression '^.*/[A-Za-z]+-[0-9]+x[0-9]+\.[A-Za-z]+$' from the current directory tree
find -regex '^.*/[A-Za-z]+-[0-9]+x[0-9]+\.[A-Za-z]+$' | xargs echo rm -f
display all directories in the folder Symfony
find Symfony -type d
Split "$1" into files of at most "$2" or default 10000 using a numeric suffix of length 6
split -l ${2:-10000} -d -a 6 "$1"
Silently read a single character from standard input into variable "key" without backslash escapes and using the prompt $'Press any key to continue...\n'
read -rsp $'Press any key to continue...\n' -n 1 key
Print the minimum transmission time of 10 ping requests to "google.com" from cygwin
ping google.com -n 10 | grep Minimum | awk '{print $3}' | sed s/,//
Find all files named "filename" in the current directory tree, not descending into "FOLDER1" directories
find . '' -print
Find all the files that were modified more than one day ago
find . -mtime +1
display all normal / regular files in current folder in reverse order
find . -type f | tac
Look in /home/dm and below for files with 'uniform' in their names
find /home/dm -name "*uniform*"
Copy all files that match 'FooBar' in their paths under current directory tree to the '~/foo/bar' directory
find . | grep "FooBar" | tr \\n \\0 | xargs -0 -I{} cp "{}" ~/foo/bar
Test if a file named 'file' in the current directory is more than 1 hour old
find file -chour +1 -exit 0 -o -exit 1
Go to /the/project/root//data, which in most filesystems/operating systems will be the same as cd /the/project/root/data
cd /the/project/root//data
same as above example with -exec , in this example with -OK it should ask for confirmation before executing the rm command . that is called user intractive command
find . -name core -ok rm {} \;
Find directories modified in last 7 days
find . -mtime -7 -type d
Find all files that are modified in last 3 days
find . -type f -mtime -3
delete all files that have the extension "bam" in current directory
find . -name "*.bam" | xargs rm
Print which files differ between dir1 and dir2, treating absent files as empty
diff --brief -Nr dir1/ dir2/
Remove lines matching "kpt#" from "data.txt" and add left-justified line numbers
grep -v 'kpt#' data.txt | nl -nln
Read the first line of output from "du -s $i" into variable "k" in ksh
du -s $i | read k
Print the current date followed by ": $line"
echo "$(date): " $line
List all IP addresses assigned to current hostname, pausing for user interaction after each page.
more /etc/hosts | grep '[[:space:]]*'`hostname`'[[:space:]]*' | awk '{print $1}'
Find all *gz files under asia and emea directory
find asia emea -type f -name "*gz"
Change permissions for all PHP files under the current directory tree to 755
find . -name "*.php" -exec chmod 755 {} \;
Calculate md5 checksum of '/etc/localtime' and save the first space separated part in variable 'checksum'
checksum=`md5sum /etc/localtime | cut -d' ' -f1`
Find all files under current directory, calculate their md5sum
find . -type f -print0 | parallel -0 -X md5sum
change the owner of the files which belong to the group 1000 to username and modify only the symbolic link not the originally pointed file
find -gid 1000 -exec chown -h :username {} \;
Find files in the current directory tree whose size is less than 24000 bytes
find . -size -24000c
Numerically sort file "file.dat" by the second word of each line and output from greatest value to least value
sort -nrk 2,2 file.dat
Reversibly sorts content of the '${TMP}/${SCRIPT_NAME}.name' file
cat ${TMP}/${SCRIPT_NAME}.name|sort -r;
Forcibly removes ${temp} file.
rm --force "${temp}"
Prints Kb size of all top-level files and folders in a current folder in descending order.
du -ks * | sort -n -r
Locate files whose status was changed less than 1 day ago
find . -ctime -1 -print
Move all hidden files in "wordpress" to the current directory
mv wordpress/.* .
Search the /tmp directory tree for files owned by user `ian'
find /tmp -user ian
Find all files/directories with spaces in their names under ~/Library directory
find ~/Library -name '* *'
Search only for regular files
find -type f
For each line which has a common first field in test.1 and test.2, output the first 2 fields of test.2 and the field 2 and 3 of test.1
join -j1 -o 2.1,2.2,1.2,1.3 <(sort test.1) <(sort test.2)
download a file "http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip" using cookies "oraclelicense=accept-securebackup-cookie"
curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip
list all regular files which path is not dir1 or dir2
find dir -not \ -type f
Find all *.txt, *.html files under /basedir that match the case insensitive pattern *company* in their names
find /basedir/ \( -iname '*company*' -and \( -iname '*.txt' -or -iname '*.html' \) \) -print0
Print the date formatted with "%a %x %X" followed by the host name
echo `date +"%a %x %X"` `hostname`
Move all files including hidden files and excluding ".." in "/path/subfolder/" to "/path/"
mv /source/path/{.[!.],}* /destination/path
search for the files "foo.txt" in the current folder and rename it to foo.xml
find -name foo.txt -execdir rename 's/\.txt$/.xml/' '{}' ';'
Find files in entire file system that are writable by group or other
find / -perm /g=w,o=w
Write the list of all files on the system to "masterfilelist.out"
find / -print > masterfilelist.out
display all files in the current folder and do not search in the sub directories
find . -maxdepth 0
set variable r to currently running kernel release, ie. 4.4.0-81-generic
r="$"
count the lines of java code for all the java files in the current directory
find . -name "*.java" -print0 | xargs -0 wc
Join data in file1 containing one number per line with data in file2 containing a number and other information per line, keeping the same order as it is found in file1.
join -1 2 -2 1 -a1 < < | sort -k2 | cut --complement -d" " -f2
Make directories "$@" verbosely and replace "mkdir: created directory " with "jar-jar: yea, weesa gotta " in the output
mkdir -v "$@" | sed 's/mkdir: created directory /jar-jar: yea, weesa gotta /'
search all the files in the current folder using regex excluding those that are present in the folder test
find . -name test -prune -o -regex ".*/my.*p.$"
Find all directories under and below /home/admin/public_html/, and change their permissions to 755
find /home/admin/public_html/ -type d -exec chmod 755 {} \;
Find all files/directories under current directory tree with '.old' extension
find . -name ”*.old” -print
find all the files that have been modified in the last 4 days and copy them to folder.
find . -mtime 4 -daystart -exec cp -a {} /home/devnet/fileshare\$ on\ X.X.X.X/RECOVER/ \;
Join lines in file "aa" with lines in file "bb" if the lines share a common first word
join < <
Find all files under current directory and run /tmp/clever.sh for each of them with each file path as an argument
find . -type f -exec /tmp/clever.sh {} \;
Find all *.mp4 files under /foo/bar and move them to /some/path
find /foot/bar/ -name '*.mp4' -exec mv -t /some/path {} +
find not case sensitive all directories that names are 'apt'
find / -type d -iname "apt"
Split "$SOURCE_FILE" into files of at most 100 lines each
split -l 100 "$SOURCE_FILE"
Find all files/directories under test directory
find test
find all the files in the current folder that have been modified in the last 7 days
find -mtime -7 -daystart
Find all files/directories following symbolic links under current directory tree that are owned by 'root' user
find . -follow -uid 0 -print
Recursively search for all files with names ending with "_test.rb", renaming them to end with "_spec.rb", using at most 1000000 characters per command.
find . -name "*_test.rb" | xargs -s 1000000 rename s/_test/_spec/