nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Do not mark variables and function which are modified or created for export to the environment of subsequent commands
set +a
Find regular files under and below /path that match pattern "???-???_[a-zA-Z]*_[0-9]*_*.???"
find /path -type f -name "???-???_[a-zA-Z]*_[0-9]*_*.???"
Find all *.dbf files/directories in entire file system discarding errors and print their sorted and unique parent directory paths
find / -name \*.dbf -print0 2>/dev/null | xargs -0 -n1 dirname | sort | uniq
display a long listing of all the normal/regular files in the current folder
find . -type f -print0 | xargs -0 ls -l
Find all files in the file system with the SUID bit
find / -perm -u+s -print
Find all directories under current directory tree that match the case insensitive regex '^\./course\*[0-9]$' in their paths
find . -type d -iregex '^\./course\*[0-9]$'
find the file "dateiname" in the entire file system ( case insensitive search)
find / -iname "Dateiname"
Read a line from standard input into variable "foobar" and suppress showing user input
read -s foobar
Print each character in "Hello" as a hexadecimal value
echo -n "Hello" | od -A n -t x1
Find all executable files under current directory and show a few lines of output from the beginning
find . -perm /a=x | head
Write the lines appended to "xxxx" as it appears to the console and append to "yyyy" in the background
tail -F xxxx | tee -a yyyy &
Find all files/directories containing 'farm' in their names under '/usr/share' directory tree
find /usr/share -name '*farm*'
display all the files in the current folder except those whose name is "PERSONAL"
find . -name PERSONAL -prune -o -print
display all the users in the current folder which do not belong to the user root
find . ! -user root
Save the system host name in variable "HOSTNAME"
HOSTNAME="`hostname`"
Save number of lines in '/some/big/file' to 'LINES' variable
LINES=$(cat /some/big/file | wc -l)
Find all regular files in the current directory tree that are not readable by all
find -type f ! -perm -444
Find files in and below the current directory whose names begin with "not" and remove one of them
find . -name not\* | tail -1 | xargs rm
Recursively finds all '*.pdf' files in a current folder and removes them.
find . -name "*.pdf" -print0 | xargs -0 rm
Recursively finds in all folders but "./output/*" all files but *.o, *.swp and prints strings with 'soc_attach' text pattern and number of matched string.
find . \( ! -path "./output/*" \) -a \( -type f \) -a \( ! -name '*.o' \) -a \( ! -name '*.swp' \) | xargs grep -n soc_attach
Prints message info about filename and location of the current script
echo "The script you are running has basename `basename $0`, dirname `dirname $0`"
Replace all occurrences of 'previousword' with 'newword' in all regular files with '.cpp' extension under '/home/www' directory tree and modify them in-place
find /home/www -type f -name '*.cpp' -exec sed -i 's/previousword/newword/g' '{}' \;
delete all the log files which have not been modified in the last 5 days after user confirmation
find . — name "*.LOG" — mtime +5 -ok rm {} \;
Send SIGTERM signal to last process sent to background by the current shell.
kill $!
Remove leading and trailing space from lines in file 'in.txt', interactively page through a hexdump of the result.
awk '{gsub; print;}' in.txt | hexdump -C | less
display long listing of all files in the current directory whose size is 24 or 25 bytes.
find . -size -26c -size +23c -ls
Set variable 'path' to name of current directory .
path=$(basename $)
Search in current directory downwards all files whose owner is aa1 or whose name is myfile .
find . \ -print
display all the files in the current folder which have been modified between two dates
find . -newermt “Sep 1 2006” -and \! -newermt “Sep 10 2006”
Execute "ls -l" every 0.5 seconds
watch -n 0.5 ls -l
find all the mp3 files in the file system
find / -iname "*.mp3" -print
Find all files called "INPUT.txt" in the current directory tree and remove lines starting with # in them, saving backup copies as INPUT.txt.bak
find . -type f -name INPUT.txt -print0 | xargs -0 -I {} sed -i.bak '/^#/d' {}
Find all directories under /home/me
find /home/me -type d
Replace " " with " $UID " in the output of "history"
history | sed "s/ / $UID /"
Count the toal number of lines in all .py files in current directory tree
find . -name *.py -exec wc -l {} \; | awk '{ SUM += $0} END { print SUM }'
Search directory /home/ABCD recursively, starting from one level below, for regular files
find /home/ABCD/ -mindepth 1 -type f -print
Find all files in the current directory tree with extension .html and replace all occurences of "php" with "html" inside them
find ./ -type f -name *".html" | xargs sed -i "s/php/html/g"
Find all the regular files in $DIR directory tree which have not been modified in the last 450 days and delete them
find $DIR -type f -mtime +450 -exec rm {} \;
Print 'infile' content with line numbers
cat -n infile
Recursively finds file some_file_name.xml file and prints strings with "PUT_YOUR_STRING_HERE" preceding each found string with file name.
find . -type f -name some_file_name.xml -exec grep -H PUT_YOUR_STRING_HERE {} \;
Delete all files/directories older than 48 hours in /path/to/files* paths
find /path/to/files* -mtime +2 -delete
Mathematically sum each line in "infile"
paste -s -d+ infile | bc
Delete all filename* files under /dir directory
find /dir -name "filename*" -type f -delete
Find & calculate total number of caractor in all .txt file from current directory
find . -type f -name '*.txt' -exec wc -c {} \; | awk '{total += $1} END{print total}'
display list of all the files in the current directory
find | xargs ls
Interactively create a symbolic link in the current directory for "$SCRIPT_DIR/$FILE"
ln --symbolic --interactive $SCRIPT_DIR/$FILE
Search the current directory tree for all files matching pattern "*.rb"
find . -name "*.rb"
Copies file 'index.html' to each top-level directory in the current directory beginning with 'd'.
find . -mindepth 1 -maxdepth 1 -type d| grep \/a |xargs -n 1 cp -i index.html
Print the full real path of "/dev/disk/by-uuid/$1" followed by "is mounted"
echo $ is mounted
search for all the regular/normal mp3 files in the file system and move them to the folder /mnt/mp3
find / -iname "*.mp3" -type f | xargs -I '{}' mv {} /mnt/mp3
Split the output of "tar [your params]" into files of at most 500 MiB in size and use prefix "output_prefix"
tar [your params] |split -b 500m - output_prefix
Find recursively the latest modified file in the current directory
find . -type f | xargs ls -ltr | tail -n 1
Force create a symbolic link in "/usr/bin/" for each file matching "$javaUsrLib/jdk1*/bin/*"
sudo ln -f -s $javaUsrLib/jdk1*/bin/* /usr/bin/
Print the first 2 lines of tree's help message by redirecting it from standard error to standard output
tree --help 2>&1 | head -n2
Abort the shell or script on the first failed command
set -e
change the current working directory to "B" and display all the files in that folder and append the output to the file "tmp.txt"
cd B && find . >> ../tmp.txt
Find all .gif files in the /var/www directory tree
find /var/www -name *.gif
Find all directories named "D" in the current directory tree
find ./ -type d -name 'D'
Search the current directory tree for the files with extension "trc" and remove them if they are more than three days old
find . -name "*.trc" -ctime +3 -exec rm -f {} \;
Decompress 'file.gz' to standard output and execute the output in bash
gzip -d --stdout file.gz | bash
Find a directory named 'project.images' in the entire filesystem
find / -type d -name "project.images"
Read a line from standard input into variable "SSHPASS" with prompt "Password: " and without echoing the input
read -p "Password: " -s SSHPASS
Find all the files named 'vimrc' anywhere on the system
find / -name vimrc
Locate OGG files under the home directory smaller than 100 megabytes
find $HOME -iname '*.ogg' -type f -size -100M
Find all files under minimum 1 level down the current directory
find . -mindepth 1 -type f
find all directories with the name root in the entire file system.
find / -type d -name root
Find all .gz archives in the current directory tree and check if they are valid
find "*.gz" -exec gunzip -vt "{}" +
Find all regular files on the system whose size is greater than 20000k
find / -type f -size +20000k
Lists all files in a current folder, separating names with comma.
ls -1 | tr '\n' ',' | sed 's/,$/\n/'
search for the file "abc" in the current folder or display all the directories
find . -name abc -or -type d
Search the ~ and `Music' directory trees for .mp3 files
find ~ Music -name '*.mp3'
Send 5 pings to broadcast address "10.10.0.255" and print the unique IPs who responded
ping -c 5 -b 10.11.255.255 | sed -n 's/.* \([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p' | sort | uniq
Locate all the hard links of file `passwd'
find / -samefile passwd
Find all build* directories under /var/www/html/ and print all but first 5 appending with the string 'rf '
find /var/www/html/ -type d -name "build*" | sort | tail -n +5 | xargs -I % echo -rf %
Find all the regular files under $DIR directory tree which have been modified before the file $a excluding the file $a and delete them
find "$DIR" -type f \! -newer "$a" \! -samefile "$a" -exec rm {} +
Find all symbolic links under '/proc/$pid/fd' directory tree with name pattern '$save_path/sess_\*' and update their timestamps
find "/proc/$pid/fd" -ignore_readdir_race -lname "$save_path/sess_\*" -exec touch -c {}
Creates temporary file with name formatted like '.script.XXXXXX' in '/tmp/' folder and saves path to it in 'script2' variable.
script2=`mktemp /tmp/.script.XXXXXX`;
reverse both words and lines in file
tac filename | perl -lane 'print join(" ", reverse)'
Search the ~/Books directory recursively for regular files named "Waldo"
find ~/Books -type f -name Waldo
search for the file filename in the entire file system
find / -name filename
Calculate the sum of all the numbers from -5 to 10
seq -s+ -5 10 | bc
Gets state of shell option 'dotglob' and saves it in 'rest_cmd' variable.
rest_cmd=$
Remove all files that end with 'prefs copy' in their names under '/mnt/zip' directory tree
find /mnt/zip -name "*prefs copy" -print | xargs rm
Replace all spaces with underscores in file paths under current directory.
find -name "* *" -type f | rename 's/ /_/g'
Find all file in current directory with have .c extenstion & have 777 permission . delete then
find . -name "*.c" -a -perm -777 | xargs rm -rf
search for MP3 files in the current folder and subfolders except in dir1 subfolder.
find ! -path "dir1" -iname "*.mp3"
show all the files in the folder /etc which have been modified in the last 24 hours
find /etc -mtime -1
Write the current date and time followed by " 0" to the console and append to "log.csv"
echo $(date) "0" | tee -a log.csv
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 {} \;
Print the file sizes along with their paths for all *.txt (case insensitive) files/directories under current directory tree
find . -iname "*.txt" -exec du -b {} +
List files in the current directory
find . \
Saves date of the first Sunday in month $mo of year $yo in the 'do' variable.
do=$(cal -m $mo $yo|awk 'NR>2&&!/^ /{print$1;exit}')
Find all hard links to file1 under /home directory
find /home -xdev -samefile file1
Interactively page through a list of all processes running on the system - the arrow keys pan around, and the Q key quits.
ps aux | less -S
Print all files and directories in the `.' directory tree skipping SCCS directories but printing out the SCCS directory name
find . -print -name SCCS -prune
Search the *.pdf files from directory tree PDFs/ for text "perry sound", ignoring the case, and print the list of matched files
find PDFs/ -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep -l -i --with-filename --label="{}" --color "perry sound"' \;
Archive preserving permissions and ownership files in "/var/www/" on host "[email protected]" to local "/var/www/"
sudo rsync -az [email protected]:/var/www/ /var/www/
Print all directories under $root appending a : at the end of each path
find $root -type d -printf '%p:'
Find all thumb.png files in the temps/ directory tree
find temps/ -name "thumb.png"
display list of all the files in the current directory
find -print0 | xargs -0 ls