nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Unsets environment variable represented as var=value by $a.
unset $
find all the text files in current folder and change the extension of these files and move them to another folder
find . -name "*.txt" | xargs -I{} sh -c 'base=$ ; name=${base%.*} ; ext=${base##*.} ; mv "$1" "foo/${name}.bar.${ext}"' -- {}
Delete all files with indoe number $inum under current directory tree
find . -inum $inum -exec rm {} \;
search in the current directory for any file named Chapter1.txt
find . -name Chapter1 -type f
List file contents of compressed file $i
gzip -l $i
Numerically sort standard input by the second word of each line
sort -n -k 2
search for *.log files starting from / (root) and only in the current file system
find / -xdev -name "*.log"
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name vmware-*.log | xargs rm
find all the directories in the current folder which begin with the words "kt" and end with a digit
find . -regex './kt[0-9] '
Find files/directories named 'TEST_3' under current directory tree
find -name TEST_3
Remove trailing spaces from the output of 'hg st -R "$path"' and save the result in variable "var"
var=`hg st -R "$path" | sed -e 's/ *$//'`
search for the word "put" in all the files in the current folder which have the word "bills" in their name and display the matched line along with the filename.
find . -name '*bills*' -exec grep -H "put" {} \;
Find all empty files starting from the current directory and delete them
find . -type f -empty -print0 | xargs -0 /bin/rm
Print the largest 20 files under current directory
find . -type f -printf '%s %p\n' | sort -rn | head -20
Find all *.texi files in /usr/local/doc
find /usr/local/doc -name '*.texi'
Search the directories given as arguments to the Bash script for files whose name is not "ss"
find $@ -not -name ss
Find all files/directories containing the case insensitive string something' in their names under current directory tree
find . -iname '*something*'
Find files in the /var/log folder which were modified an hour or more ago
find /var/log/ -mmin +60
Find all empty files under a certain path
find /tmp -type f -empty
ERROR - Probably means -pgoDt
sudo rsync -pgodt /home/ /newhome/
search for a word in all the files in the current directory
find . | xargs grep 'chrome'
Search the current directory tree for regular files whose names match regular expression ".+-[0-9]+x[0-9]+\.jpg"
find . -type f -regex ".+-[0-9]+x[0-9]+\.jpg"
Make directory expanded by $dir variable
mkdir $dir
Find all files starting from the current directory which are smaller than 100MB
find . -size -100M
Returns exit code 1.
false
Find all 15MB files
find / -size 15M
Cuts off last two parts from the path $dir, and deletes resulted folder if empty.
rmdir "$(dirname $)"
Find all 'test' directories in the current directory tree
find -type d -a -name test
find all the files in the entire file system that have been modified exactly 50 days ago
find / -mtime 50
Evaluate the output of recursively changing the owner and group of "/data/*" to "mongodb"
`sudo chown -R mongodb:mongodb /data/*`
Write "Some console and log file message" to standard output and "/dev/fd/3"
echo "Some console and log file message" | tee /dev/fd/3
Find all files and directories whose names end in ".rpm", ignoring removable media, such as cdrom, floppy, etc.
find / -xdev -name \*.rpm
Search for "LOG" in jsmith's home directory tree
find ~jsmith -exec grep LOG '{}' /dev/null \; -print
Decompress "/file/address/file.tar.gz" to standard output
gzip -dc /file/address/file.tar.gz
Find all file paths under current directory, perform a reverse sort and show first 10 file paths with their status change time
find . -type f -printf "%C@ %p\n" | sort -r | head -n 10
split the result of command "ping -c 25 google.com | tee " into pieces per 100000 bytes named as "/home/user/myLogFile.logNNN"
ping -c 25 google.com | tee >
Ping the broadcast address "10.10.0.255"
ping -b 10.10.0.255
Find files in the current directory tree which have permissions rwx for user and rw for group and others
find . -perm 766
Print extended file information for regular files found under the home directory whose names start with my
find . -name 'my*' -type f -ls
Find files/directories named 'sar' under '/usr', '/bin', '/sbin' and '/opt' directory tree
find /usr /bin /sbin /opt -name sar
display all files in the current folder that have been modified in the last 24 hours whose name has only 1 letter
find . -name \? -mtime -1
From the list of words in list1.txt, display the number of occurrences of this word in list2.txt and sort the results from highest to lowest count.
grep -Ff list1.txt list2.txt | sort | uniq -c | sort -n
list all javascipts file which whole name does not contain excludeddir
find . -name '*.js' | grep -v excludeddir
Unzip and untar "openssl-fips-2.0.1.tar.gz"
gunzip -c openssl-fips-2.0.1.tar.gz | tar xf ­-
Find all regular files with permissions 777 under and below /home/user/demo/
find /home/user/demo -type f -perm 777 -print
Delete all files in the /myDir directory tree that were last modfied 7 days ago
find /myDir -mindepth 1 -mtime 7 -delete
find all the xml files in a directory and pass it as an argument to a jar
find /dump -type f -name '*.xml' -exec java -jar ProcessFile.jar {} \;
Replace all non-punctuation characters with newlines from standard input
tr -sc '[:punct:]' '\n'
Search the ./in_save directory for regular files and view the result using pager `more'
find ./in_save/ -type f -maxdepth 1| more
display the names without extensions of all the data files in current folder and do not search in sub folders and which have not been changed in the last 60 mins
find . -maxdepth 1 -name '*.dat' -type f -cmin +60 -exec basename {} \;
search for the directory "config" in the current folder and change directory to the first instance of the search
cd $
Find a single file called tecmint.txt and remove it
find . -type f -name "tecmint.txt" -exec rm -f {} \;
Print file information of command "studio"
ls -l "$( which studio )"
Find all regular files in the current directory and its subdirectories.
find . -type f
search for all the files in the current folder which are bigger than 10KB and display them biggest file
find . -size +10k -exec ls -ls {} \+ | sort -n | tail -1
Search for .pdf files
find / -name '*.pdf'
Print variable "$module" in formatted columns
column <<< "$"
Search the current directory recursively for regular files last changed less than 2 days ago
find . type -f -ctime -2
Change permissions to 644 for all regular files under the /path/to/dir/ tree
find /path/to/dir/ -type f -print0 | xargs -0 chmod 644
Print the list of files in directory /tmp/a1 recursively
find /tmp/a1
find all the normal/regualar files in the current folder which have a size of 10KB and display a long listing details of them.
find . -type f -size +10000 -exec ls -al {} \;
Reverse the space separated words in "aaaa eeee bbbb ffff cccc"
echo "aaaa eeee bbbb ffff cccc"|tr ' ' '\n'|tac|tr '\n' ' '
Remove leading and trailing spaces or tabs from " wordA wordB wordC "
echo " wordA wordB wordC " | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//'
Gets string with MAC address of eth0 network interface.
ifconfig eth0 | grep HWaddr
Print mount point of the file system containing $path.
df -P "$path" | tail -1 | awk '{ print $NF}'
Unzip "doc.gz" and gzip every 1000 lines
zcat doc.gz | split -l 1000 --filter='gzip > $FILE.gz'
Search for files in your home directory which have been modified in the last twenty-four hours
find $HOME -mtime 0
split result of the command "tar [your params]" into pieces per 500 mb named as "output_prefixNNN"
tar [your params] |split -b 500m - output_prefix
Prints message info about filename and location of the current script
echo "The script you are running has basename `basename $0`, dirname `dirname $0`"
List the 10 largest files or directories and their sizes under "/var"
du -a /var | sort -n -r | head -n 10
find all files that names are 'apt'
find / -name "apt"
Split all files in the directory tree "/dev/shm/split/" into files of at most 1000 lines each and use the filename as the prefix
find /dev/shm/split/ -type f -exec split -l 1000 {} {} \;
Decompress ${set1[@]} files with gzip
gzip -d ${set1[@]} &
Mount "ext4" filesystem "/dev/xvdf1" on "/vol"
sudo mount /dev/xvdf1 /vol -t ext4
Delete all empty subdirectories in and below directory/
find directory -mindepth 1 -type d -empty -delete
Decompress and sort "$part0" and "$part1" of files in different processes
sort -m <(zcat $part0 | sort) <(zcat $part1 | sort)
Print the number of packets sent, received, and the percentage lost for each ping request to "google.com"
ping google.com | awk '{ sent=NR-1; received+=/^.*.*$/; loss=0; } { if loss=100-(*100) } { printf "sent:%d received:%d loss:%d%%\n", sent, received, loss }'
Move all files and directories in the current directory to "somewhere/"
mv `ls` somewhere/
Shows state of 'globstar' shell option.
shopt globstar
Find all files under current directory and change their permission to 600
find . -type f -exec chmod 600 {} \;
Clear the in-memory history and read from the current history file
history -cr
Find all files/directories under current directory tree whose names start with '' followed by two digits and end with '.txt' extension
find . -regex ".*/[0-9][0-9]\.txt"
Prints help on 'yum' utility.
yum -h
List all files in the current directory tree invoking xargs only once
find . -type f -print | xargs ls -l
Replace all occurrences of "foo_fn" with "bar_fn" in the files named "foo_fn" from the current directory tree
find . -name foo_fn exec sed -i s/foo_fn/bar_fn/g '{}' \;
Display mimetype of myfile.txt.
file --mime myfile.txt
Force delete all the regular/normal files in the current folder and do not search in the sub folders
find . -maxdepth 1 -type f -exec rm -f {} \;
Remove all .sh files in the current directory tree whose names begin with "new"
find . -name "new*.sh" -exec rm -f '{}' \+
Print name of the file system containing $path.
df -h $path | cut -f 1 -d " " | tail -1
Append the date and command ran to "/tmp/trace" after every command
PROMPT_COMMAND='echo "$(date +"%Y/%m/%d ") $" >> /tmp/trace'
Remove all regular files under $DIR directory tree that were accessed more than 5 days ago
find "$DIR" -type f -atime +5 -exec rm {} \;
display all the directories in the current folder excluding those that are present in the folder secret
find . -name secret -type d -prune -o -print
wait 2 seconds and then print "hello"
echo "hello `sleep 2 &`"
Find all files with '.jpg' extension in the current directory ignoring sub-directories and archive them to a file named jpeg.tgz
find . -maxdepth 1 -iname "*.jpg" | xargs tar -czvf jpeg.tgz
Receive input and print it to terminal
cat
Print the directory of the full path to the current script
echo $(dirname $)
Find all files/directories under current directory tree whose paths start with './sr' and end with 'sc'
find . -path './sr*sc'
Show the list of files that are owned by user wnj or are newer than file `ttt'
find / \ -print
Replace spaces with underscores in the names of all files and directories in the "/tmp" directory tree
find /tmp/ -depth -name "* *" -execdir rename " " "_" "{}" ";"
Set the permissions of all directories inside the current directory tree to ug=rwx,o=
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;