nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all regular files under $FOLDER directory tree that start with '".' and end with '"' in their names and were modified in less than $RETENTION days excluding the files whose contents match one of the regular expressions defined per line in file $SKIP_FILE
find ${FOLDER} -type f ! -name \".*\" -mtime -${RETENTION} | egrep -vf ${SKIP_FILE}
Search the current directory tree for executable regular files
find . -type f -executable -exec file {} \; | grep -wE "executable|shared object|ELF|script|a\.out"
Save the user name of the current user to variable "x"
x=$
Allow ssh from 127.0.0.1 on port "someport" through "proxy.host" to "host.in.the.remote.net" on port 22
ssh -fL 127.0.0.1:someport:host.in.the.remote.net:22 proxy.host
search for the word "methodNameHere" in all the python files in the folder "/mycool/project/" and display color on the matched lines in the output
find /mycool/project/ -type f -name "*.py" -print0 | xargs -I {} -0 grep -H --color "methodNameHere" "{}"
Show manual page of find
man find
If directory "mydir" exists in user's home directory, run "mycommand" in it, without changing the current shell's working directory, but do nothing if no such directory exists.
Recursively change owner and group to "tomcat7" of "webapps", "temp", "logs", "work", and "conf"
chown -R tomcat7:tomcat7 webapps temp logs work conf
Recursively change the owner to "$USER" and group to "$GROUP" of "/var/lib/cassandra"
sudo chown -R $USER:$GROUP /var/lib/cassandra
Print the basename from a colon separated path 'a:b:c:d:e'
basename $
Print the output of history without line numbers
history|awk '{$1="";print substr}'
Saves exit statuses of piped commands in a system variable PIPESTATUS='([0]="0" [1]="1" [2]="0")'
true | false | true
Find and show all files on the system that are larger than 900 MB
find / -size +900M
Count all the mp3 files in the music user's home and subdirs.
find ~music -type f -iname *.mp3 | wc -l
Reports count of characters in the value of ${FOO_NO_LEAD_SPACE} variable as follows: "length(FOO_NO_LEAD_SPACE)==<counted number of characters>"
echo -e "length(FOO_NO_LEAD_SPACE)==$(echo -ne "${FOO_NO_LEAD_SPACE}" | wc -m)"
Update timestamps of all regular files (ie. excluding directories, symlinks, sockets, etc.) under /your/dir
find /your/dir -type f -exec touch {} +
Find all *.ogg files/directories under your home directory that are greater than 100MB in size
find $HOME -iname '*.ogg' -size +100M
find files in current folder using name patterns and sort the display the file names in the sorted order
find . -name "S1A*1S*SAFE" | rev | awk -F '/' '{print $1}' | rev | sort -t _ -k 5
List .html files in the current directory tree that contain string "base\-maps" but do NOT contain string "base\-maps\-bot"
find . -name "*.html" -exec grep -lR 'base\-maps' {} \; | xargs grep -L 'base\-maps\-bot'
Search every directory except the subdirectory excluded_path for a regular file 'myfile'
find / -path excluded_path -prune -o -type f -name myfile -print
Count the number of files named 'job.history' under '/data/SpoolIn' directory tree that match 'FAIL' in their contents
find /data/SpoolIn -name job.history -exec grep -l FAIL {} \+ | wc -l
Remove all non-hidden files in the current directory tree
find -name "*" | xargs rm -f
Print full path of command "gradle"
which gradle
find in the entire file system for the file mysql
sudo find / -name mysql -print
Find all files called wp-config.php in the /var/www directory and below
find /var/www/ -name wp-config.php
search for the file "dok.txt" in the kat folder and if it sis present then print the echo statement
find kat -name dok.txt -exec bash -c 'echo -e "\nAutor: Jan Kowalski" >> {}' \;
Connect to host "server_b" as ssh user "user" and copy local file "/my_folder/my_file.xml" to server_b's directory "/my_new_folder/".
scp -v /my_folder/my_file.xml user@server_b:/my_new_folder/
Find empty files under test directory
find test -empty
search for all regular/normal files in the current folder and display the number of lines in the file
find . -type f -print | xargs -L1 wc -l
find all the php files in current folder and search for multiple patterns in these files and display the file names
find -name '*.php' -exec grep -in "fincken" {} + | grep TODO | cut -d: -f1 | uniq
Saves listing of a current folder in 'var' variable.
var=$(ls -l)
use find -exec with multiple commands regardless of their success or failure
find . -name "*.txt" \ -exec grep banana {} \;
show the list of all the files in the current folder which have been modified within the 24 hours
find . -mtime 0 -print
Find all file paths under current directory, sort them numerically and show last 10 lines of output with only their paths
find . -type f -printf '%T@ %p\n' | sort -n | tail -10 | cut -f2- -d" "
Find all files named "file.ext" in the current directory tree and print the path names of the directories they are in
find . -name "file.ext" -execdir pwd ';'
Find all files in the current directory tree containing "foo" in their names
find . -print | grep -i foo
Archive any files changed in the last day from "remote_host" to "local_dir"
rsync -av remote_host:'$(find logs -type f -ctime -1)' local_dir
set alias "foo" for command "printf"
alias foo="printf"
Counts all lines in $i file.
cat $i | wc -l
Find all .txt files in the current directory tree and save their path names to /tmp/logfile
find /full/path/to/dir -name '*.txt' -print0 | xargs -0 >/tmp/logfile
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
Search the .java files from the current directory tree for TODO lines
find . -name "*.java" -exec grep -Hin TODO {} \;
Display variable 'var' without leading and trailing whitespace.
echo $var | awk '{gsub}1'
Inserts "new line" after last occurrence of ScriptAlias in a file
tac file | awk '/ScriptAlias/ && ! seen {print "new line"; seen=1} {print}' | tac
Infinitely write "1" with line numbers to the console and "/tmp/to"
yes 1 | nl | tee /tmp/to
Recursively change ownership of "/usr/local/lib/node_modules" to the current user
sudo chown -R `whoami` /usr/local/lib/node_modules
Read line from file descriptor 4 and store received input in 'line' variable
read -u 4 line
Find all files/directories under /eserver6 directory and follow symlinks if needed
find /eserver6 -L
Print the full real path of "/dev/disk/by-uuid/$1" followed by "is not mounted"
echo $ is not mounted
display all the directories in the current folder excluding those that are present in the aa directory tree
find . -type d -name aa -prune -o -print
Delete all files/directories under current directory
find -delete
Recursively change the owner to "${JBOSS_USER}" of "$JBOSS_LOG_DIR"
chown -R ${JBOSS_USER}: $JBOSS_LOG_DIR
display the three largest files by size in current folder
find . -type f -exec ls -s {} + | sort -n -r | head -3
Find all directories under current directory and run /path/to/script.sh for each of them
find . -type d -exec /path/to/script.sh \{} \;
find a 'fool.scala' named regular file under /opt /usr /var those directories.
find /opt /usr /var -name foo.scala -type f
Find all `doc.txt' files in the current directory tree printing "found" for each of them
find ./ -name doc.txt -printf "found\n"
Find all file1 and file9 files/directories under current directory
find . -name file1 -or -name file9
Find all files under /path/you/need, calculate their md5sums and redirect the results to checksums.md5
find /path/you/need -type f -exec md5sum {} \; > checksums.md5
Find all identical files in the /usr directory tree that are bigger than 10000 bytes and write the result to usr.dups
find /usr -type f | samefile -g 10000 >usr.dups
find file which name like 'foo.*' in current directory.
find . -name "foo.*"
List all your files including everything in sub-directories
find ~
Display the mimetype of "filename"
file -i filename
Search the current directory recursively for regular files last accessed more than 2 days ago
find . type -f -atime +2
Save a line of 100 random characters either "." or " " in variable "foo"
foo=$
Print DISPLAY of "orschiro" user
who | sed -e '/orschiro/! d; /pts/! d; s/^.*\(:[0-9.]\+\).*$/\1/p;d' | head -n1
find all the ".mov" files in the current folder and give it as an input to the myffmpeg.sh script file
find . -iname "*.mov" -exec /path/to/myffmpeg.sh {} \;
Remove trailing whitespaces in TXT files from the current directory tree
find . -iname '*.txt' -type f -exec sed -i '' 's/[[:space:]]\{1,\}$//' {} \+
Move all files in the current directory tree that match "some_pattern" to "target_location"
find . -name some_pattern -print0 | xargs -0 -I % mv % target_location
Split "/path/to/large/file" into files with at most 50000 lines and use prefix "/path/to/output/file/prefix"
split --lines=50000 /path/to/large/file /path/to/output/file/prefix
Open a ssh connection to user@host with X11 forwarding to run GUI programs
ssh user@host -X
Creates temporary file in default folder and saves path to it in 'source' variable.
source=`mktemp`
run somecommand with one argument for each file recursively in /path that matches 'pattern'
find /path -name 'pattern' -exec somecommand {} \;
Find all the files which are modified 50 days back
find / -mtime 50
Calculate and show md5 sums for every files under current directory tree
find . | xargs md5sum
Find all files under current directory matching the posix-egrep type regex '^.*/[a-z][^/]*$' in their names
find . -regextype posix-egrep -regex '^.*/[a-z][^/]*$' -type f
Change ownership of "/vol" to the current user
sudo chown `whoami` /vol
Archive "path/subfolder" to "path", skipping files that are newer at the destination.
rsync -vuar --delete-after path/subfolder/ path/
Read a line from standard input and save response in variable "VARNAME"
read VARNAME
Search recursively through /mydir, outputting only the base name of each file, directory, symlink etc. without any containing directories, that is the part following the last slash.
find /mydir | xargs -I{} basename {}
Make directory "~/log"
mkdir ~/log
Move *wp-admin/index.php files under /var/www/ to ./index_disabled
find /var/www/ -path '*wp-admin/index.php' -exec mv {} $(dirname {})/index_disabled
find symbolic link file that name match '*sysdep.c'
find . -lname '*sysdep.c'
Move all directories from the `sourceDir' directory tree to the `destDir' directory
find sourceDir -mindepth 1 -type d -exec mv -t destDir "{}" \+
Print the first word followed by the rest of the line formatted to fit in 100 characters for every line in "input"
sed 's/\ /\1\n/' input | fold -w 100
find *.txt files in the current directory and sub-directories
find -name "*.txt" 2>>/dev/null
Remove all .txt files in and below the current directory
find . -name "*.txt" -delete
Recursively changes group ownership of every folder in a current directory to the name of that folder.
find . -type d | sed -e 's/^\.\///g' | awk '{print $1, $1}' | xargs chgrp
Print unique lines in "file_a" and "file_b"
sort file_a file_b|uniq -u
Print only first line of 'file' content, formatted as 29-symbol wide column
cat file | fold -w29 | head -1
dispaly a list of all the files in the file system which belong to a specific user and exclude searching in the folder proc
find / -path /proc -prune -o -user <account> -ls
Find all files/directories under '/directory_path' directory tree that have been modified within the last day
find /directory_path -mtime -1 -print
Search all the regular files in the current directory tree for "example"
find -type f -print0 | xargs -r0 grep -F 'example'
display all the files in the home folder that have been modified in the last 7*24 hours
find $HOME -mtime -7
Find all *.rpm files/directories under current directory
find . -name '*.rpm'
Prints sizes of all top-level folders in a current folder with human-readable format and descending order.
du -h --max-depth=1 . | sort -n -r
Find all files/directories named 'myfile' under your home directory
find ~ -name myfile
find all the files in the current directory which have the size 40 bytes in the current disk partition.
find . -size -40 -xdev -print
Find all files under /home/username/public_html/themes and set their permission to 640
find /home/username/public_html/themes -type f -exec chmod 640 {} +
Change permissions of all files ending in ".php" under the current directory to 755 and print a count of modified files
find . -name "*.php" -exec chmod 755 {} \; -exec /bin/echo {} \; | wc -l
Recursively removes all files like '_*' and '.DS_Store' from /var/www/html/ folder.
rm /var/www/html/**/_* /var/www/html/**/.DS_Store