nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Verbosely compresses all files on third and fourth depth level keeping original files in place.
bzip2 -kv */*/*/*
Count the number of times that a single "-----------\n" separated record contains both "A=2" and "dummy=2" in compressed file "file.gz"
zcat file.gz | awk -v RS="-----------\n" '/A=2[ ,\n]/ && /dummy=2[ ,\n]/{count++} END{print "Final counter value=",count}'
Unzip every ".gz" file in the current directory
gunzip *.gz
Find all regular files with the group read permission set in your home directory and below and output detailed information about each file.
find . -perm -g=r -type f -exec ls -l {} \;
list all files in /home/bozo/projects directory tree that were modified exactly one day ago.
find /home/bozo/projects -mtime 1
Creates temporary file and saves path to it in a 'tmpfile' variable.
tmpfile=`mktemp`
find the file with the name "esxcfg-firewall" in the current folder
find -print | grep esxcfg-firewall
Page through the information of the system's PHP setup.
less -f <
Search the entire file hierarchy for files named zsh that exist on ext3 file systems and print out detailed information about the file.
find / -fstype ext3 -name zsh -ls
Find all files/directories under current directory and print them with newline as the delimiter
find -print | xargs -d'\n'
Find and delete all hard links in the /home directory to file1
find /home -xdev -samefile file1 -exec rm {} +
Run 10 bash processes at most 4 at a time of "echo start N; sleep 3; echo done N" for N ranging from 1 to 10
seq 10 | xargs -i --max-procs=4 bash -c "echo start {}; sleep 3; echo done {}"
Search the current directory recursively for regular files last accessed 2 days ago
find . type -f -atime 2
find the file with inode $inum under the current directory and delete it
find . -inum $inum -exec rm {} \;
Make directory "alpha_real"
mkdir alpha_real
remove all subdirectories named "CVS" under current dir
find . -type d -name CVS -exec rm -r {} \;
Make a list of regular files from the current directory tree that have more than 1 link and view it with the "less" pager
find . -type f -noleaf -links +1 -printf "%n %i %f\t%h\n" | sort | less
print number of jobs
n_jobs=$( jobs -p | awk '{print NR}' )
list txt files older than 5 days or html files of any age, null separated
find . \( -name '*.txt' -mtime +5 -o -name '*.html' \) -print0
Print lines 347340107 through 347340206 in "filename"
tail -n +347340107 filename | head -n 100
Search the /home/test directory tree for directories and files called '.ssh'
find /home/test -name '.ssh'
List all files in the current directory tree that were last modified more than 60 minutes ago
find -mmin +60
Print a top 20 histogram of characters used from standard input showing backslash escapes for non-displayables
od -cvAnone -w1 | sort -b | uniq -c | sort -rn | head -n 20
Print first field from semicolon-seprated line <line>.
echo "<line>" | cut -d ";" -f 1
Enables shell option 'histappend'.
shopt -s histappend
find all the files in the home folder which have been modified in the last 7 days
find $HOME -mtime -7
List environment variables and their values whose name matches '^\w*X\w*'
set | grep -P '^\w*X\w*'
Write the standard output and error of "someCommand" to the console and "someFile"
someCommand 2>&1 | tee someFile
ERROR - will overwrite the executable if it's not a symlink.
sudo ln -sf /usr/local/ssl/bin/openssl `which openssl`
Save a unique list of the currently logged in usernames to variable "line"
line=$
list all regular files which path is not dir1 or dir2
find dir -not \( -path "dir1" -prune \) -not \( -path "dir2" -prune \) -type f
List the files in "archive.tar.gz"
gzip -l archive.tar.gz
Create a hard link named "my-hard-link" to "myfile.txt"
ln myfile.txt my-hard-link
Search for "foo" in every file in the current directory and number the output
grep foo * | nl
search in current directory downwards all files whose status has changed more then 7 days ago
find . -ctime +7 -print
Create 256 directories named from '00' to 'ff', each containing 256 subdirectories named '00' to 'ff'.
join -j2 < < | xargs -n256 printf "%02x/%02x\n" | xargs mkdir -p
Truncate all regular files under the current directory
find . -type f -maxdepth 1 -exec sh -c 'cat /dev/null > {}' \;
Display kernel release name.
uname -r
Remove all files with names like "vmware-*.log" from the current directory tree
find . -name vmware-*.log -print0 | xargs -0 rm
split content of the file inputfile except lines started with "^t:" into pieces per 200 lines
cat inputfile | grep "^t\:" | split -l 200
split listing of the current directory into pieces per 500 lines named "outputXYZNNN"
ls | split -l 500 - outputXYZ.
Find all hidden regular files starting from the current directory
find . -type f -name ".*"
Installs package group "MYSQL Database Client", answering 'yes' on all questions.
yum -y groupinstall "MYSQL Database Client"
Print the first line and lines with "f" as the third "," separated field in "input" and format the result as a "," delimited table
awk -F, '{ if print}{ifprint}' input | column -t -s,
Copy all files with name pattern $j.sh under '/tmp/2' directory tree to $i directory
find "/tmp/2/" -iname "$j.sh" -exec cp {} "$i" \;
Find all *.err files under current directory that are larger than 5120 bytes in size
find . -type f -size +10 -name "*.err"
Find only files under /etc with the size of 100k-150k
find /etc -size +100k -size -150k
Print the current directory name without full path
echo "$PWD" | sed 's!.*/!!'
Print the full path of a 'file.txt' file in the current folder.
ls "`pwd`/file.txt"
Display the 5 largest files in the current directory and its sub-directories.
find . -type f -exec ls -s {} \; | sort -n -r | head -5
Report file systems disk usage, elide all entries insignificant to available space, and produce a grand total.
df --total
Search appended data in "logfile.log" for "something" with a timeout of 3 seconds
tail -f logfile.log | grep --line-buffered "something" | read -t 3
Calculate the md5 sum of the contents of "$FILES"
cat $FILES | md5sum
Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory
find /home -iname tecmint.txt
Find all files/directories under current directory tree
find | xargs
Search all files & directoy from root directory which are greater then 100M and delete them .
find / -size +100M -exec rm -rf {} \;
display all the files in the current folder which are in the path "./sr*sc"
find . -path './sr*sc'
Delete all files under user's home directory tree that were accessed more than 365 days after their status was changed
find ~ -used +365 -ok rm '{}' ';'
Remove all CVS directories in the current directory tree
find . -type d -name CVS -exec rm -r {} \;
Find all files/directories under /home/baumerf/public_html/ that were modified less than 60 minutes ago excluding error_log files/directories
find /home/baumerf/public_html/ -mmin -60 -not -name error_log
search for the directory with the name aa in the current folder
find . -type d -name aa
search for the file, filename.txt in the current folder
find . -name filename.txt
Force create a symbolic link in "/usr/bin/" for each file matching "$javaUsrLib/jdk1*/bin/*"
sudo ln -f -s $javaUsrLib/jdk1*/bin/* /usr/bin/
Get the base filename from variable 'path', similar to using the basename command.
echo "$path" | rev | cut -d"/" -f1 | rev
Print unique lines in sorted "file1" compared to sorted file "file2"
comm -23 file1 file2
Search directory tree $DIR for *.txt files
find $DIR -name "*.txt" -print
Recursively finds all folders in a current folder that contain files like '.git'.
find . -name '.git' | xargs dirname
prints first line of $bigfile
head -n1 $bigfile
Replace the occurrences of "HOGE" with "MOGA" once per each line of the files from the current directory tree, keeping a backup copy of every touched file
find . -type f -print0 | xargs -0 sed -i.bak -e "s/HOGE/MOGA/"
display a list of all the files in the file system which do not belong to any group and search only in jfs and jfs2 file systems
find / -nogroup \ -ls
Unzip "file.gz" to standard output and execute in bash with arguments "-n wordpress"
gzip -d --stdout file.gz | bash -s -- "-n wordpress localhost"
ssh into default vagrant host without running "vagrant ssh"
ssh $ localhost
Delete all files/directories named test under maximum 2 level down the current directory
find . -maxdepth 2 -name "test" -exec rm -rf {} \;
Prints only first ten characters of each string of file $file.
cat $file | cut -c 1-10
Set variable "finalName" to the second-to-last slash-separated path component of variable "path"
finalName=$(basename -- "$")
delete what was typed in the command line and run "pwd" when button "\e[24~"
bind '"\e[24~":"\C-k \C-upwd\n"'
Display what flags mount points are mounted with
mount -l
Remove files that are less than 1MB in size under current directory
find . -type f -size -1M -exec rm {} +
Print the current working directory and the base name of "$1"
echo "$(pwd)/$(basename "$1")"
display list of all the regular/normal files in the home folder which are exactly 6579 bytes
find /home/ -type f -size 6579c -exec ls {} \;
Make sure the file ".bash_profile" exists in current directory, update its timestamp to current date/time.
touch .bash_profile
Recursively removes all files and folders like 'FILE-TO-FIND' from current folder.
find . -name "FILE-TO-FIND" -exec rm -rf {} +
Find all files under directory tree /path/to/dir whose permissions are not 644
find /path/to/dir ! -perm 0644
Find files/directories that have not been modified in the last one day in directories or files taken from the glob pattern '/tmp/test/*'
find /tmp/test/* -daystart -mtime +1
find all of the executable files on your computer
find / -executable
Search the current directory recursively for .sh files whose names begin with "new"
find . -name "new*.sh"
Erase user's cron jobs and add one cron job to run "script" every minute.
echo "* * * * * script" | crontab -
Format the time string @133986838 according to the default time format and save it to variable 'VARIABLENAME'
VARIABLENAME=$(date -d @133986838)
Search the current directory recursively for files with the exact permissions u=rwx,g=rx,o=rx
find . -perm a=rwx,g-w,o-w
Print all files in the current directory tree as a comma separated list
find . -type f | paste -d, -s
Recursively change the user and group of all files in "/var/cache/jenkins" to "root"
chown -R root:root /var/cache/jenkins
Find all files and directories under current directory without crossing over to other partitions
find . -xdev -print0
Print second section of data coming from stdin where sections are separated by one or more whitespace.
tr -s ' ' | cut -d ' ' -f 2
Archive "/path/to/application.ini" on host "source_host" to current directory.
rsync -avv source_host:path/to/application.ini ./application.ini
Find all regular files under /home/www and replace every occurrences of 'subdomainA.example.com' with 'subdomainB.example.com' in those files
find /home/www/ -type f | xargs perl -pi -e 's/subdomainA\.example\.com/subdomainB.example.com/g'
Find .rm files in the /home/me/download/ directory tree and convert them to the MP3 format
find /home/me/download/ -type f -name "*.rm" -exec ffmpeg -i \{} -sameq \{}.mp3 \; -exec rm \{} \;
Enable history and history expansion within a script
set -o history -o histexpand
Copy "src/prog.js" and "images/icon.jpg" to "/tmp/package" keeping relative path names
rsync -R src/prog.js images/icon.jpg /tmp/package
Find all files/directories starting with 'onlyme' in their names under current directory tree in minimum 1 level deep
find . -mindepth 1 -name 'onlyme*'
Search the current directory tree for files named "accepted_hits.bam"
find . -name "accepted_hits.bam"