nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
search for all tar.gz compress files in the current folder
find -name *.tar.gz
Request authority info with comments for 'djzah.com' from name server 'ns1.hosangit.com', and pass it to 'script.awk' awk script.
dig @ns1.hosangit.com djzah.com +noall +authority +comments | awk -f script.awk
find all the files in the home folder that have not been modified in the last one year
find $HOME -mtime +365
Unzip and untar "4.56_release.tar.gz" to standard output
gunzip -c 4.56_release.tar.gz | tar xvf -
Count the number of lines in all ".php" files in the current directory tree using bash for Windows
cat `/gnuwin32/bin/find.exe . -name *.php` | wc -l
Extract rpm "packagename"
rpm2cpio packagename | cpio -ivd
Find all regular files with '.r' and '.c' in their names under current directory tree
find ./ -type f \( -name '*.r*' -o -name '*.c*' \) -print
Find all *.swp files/directories under current directory and print the list to a file named 'rm'
find . -name "*.swp" > rm
Change directory to the output of command '~/marker.sh go "$@"'
cd $( ~/marker.sh go "$@" )
Find all files/directores under /etc and run the file command on each of them
find /etc -print0 | xargs -0 file
Split a file "file.tar.gz" into pieces named as "file.tar.gz.part-NNN" with size 1024 MB where NNN is a numeric suffix
split -b 1024m "file.tar.gz" "file.tar.gz.part-"
Verbosely change ownership of "$file" to "root"
chown -v root "$file"
search in all the regular/normal files of the current folder for the word "word" and display the matched file name
find . -type f -exec grep -l "word" {} +
Fix files to default permissions 755
find . -type d -exec chmod 755 {} \;
Add execute permission to "ComputeDate", "col", and "printdirections" for all users
chmod a+x ComputeDate col printdirections
find all the files in the current folder ending with cpp or hpp or chpp and save the output to the file cscope.files.
find ./ -name "*.[ch]pp" -print > cscope.files
Saves byte size of $myvar variable value in the 'var2' variable.
var2=$(echo $myvar | wc -c)
Archive all files/directories under data/ into archive.tar
find data/ -print0 | tar -T - --null --create -f archive.tar
print apparent size rather than disk usage
du -B1 --apparent-size /tmp/foo.txt
Change the owner of all files in "/empty_dir/" to "root" using at most 10 files at a time
ls /empty_dir/ | xargs -L10 chown root
Print the names of all files in the home directory and its subdirectories recursively whose MIME type is video
find ~ -type f -exec file -i {} + | grep video
find all the backup files in the current folder and delete them
find . -type f -name “FILE-TO-FIND” -delete;
display the number of lines in all the ".c" files in the current folder
find . -name "*.c" -exec wc -l {} \;
Print symlink resolved script file name
echo $(basename $(readlink -nf $0))
update the permission of all the php files in current directory and save the output to a file
find . -name '*.php' -exec chmod 755 {} \; | tee logfile.txt
Delete all files with inode number 804180
find -inum 804180 -exec rm {} \
Takes folder name of file $0, changes backslashes to forward ones and saves result in $basedir variable.
basedir=$(cygpath -m "$")
Find recursively regular files in the directory given as the script's command line argument #1, skipping hidden files and directories
find "$1" -path "*/.*" -prune -o \
Send SIGHUP (hangup) signal to nginx master process, causing it to re-read its configuration and restart child processes if necessary.
kill -HUP $( cat /var/run/nginx.pid )
Unset the executable bit of all regular files from directory trees arch, etc, lib, module, usr, xpic
find arch etc lib module usr xpic -type f | xargs chmod -x
replaces the second to last line of file
tac file | sed '2 s/,$//' | tac
Find all files larger than 100M and delete them
find / -size +100M -exec rm -rf {} \;
Find all files owned by the user daniel in the current directory and below.
find . -user daniel
Display only first and second dot-separated numbers of kernel version, ie. 4.4
uname -r | cut -d. -f1-2
list all active jobs and its IDs
jobs -l
find all the directories in the entire file system whose size is greater than 50KB
find / -type d -size +50k
Search for files in your home directory which have been modified in the last twenty-four hours
find $HOME -mtime 0
Find files modified within the past 24 hours
find . -mtime 0
Search for files/directories with the case insensitive pattern anaconda.* in var/log directory and create an archive (file1.tar) of the last block of files sent to xargs
find var/log/ -iname anaconda.* | xargs tar -cvf file1.tar
Find all regular files recursively in the current directory
find . -type f
Set variable 'path' to name of current directory converted to lowercase.
path=$(basename $ | tr 'A-Z' 'a-z' )
display all the jpg files in the current folder and do not search in sub directories
find . -maxdepth 1 -mindepth 1 -iname '*.jpg' -type f
Search the current directory tree for files whose names do not end in "1" and "2"
find . -type f ! -name "*1" ! -name "*2" -print
Archive "/local/path/some_file" to "/some/path" on host "server.com" authenticating as user "usr", compress data during transmission, show progress details.
rsync -avz --progress local/path/some_file [email protected]:"/some/path/"
Delete all files in the /myDir directory tree that were last modfied 7 days ago
find /myDir -mindepth 1 -mtime 7 -exec rm -rf {} \;
search for the file "job.history" in the folder /data/Spoolln and search for multiple patterns in the file and display the count of matched lines along with the pattern
find /data/SpoolIn -name job.history | xargs grep -o -m 1 -h 'FAIL\|ABOR' | sort | uniq -c
Recursively set all permissions under "/whatever/your/directory/is" to 755
sudo chmod 755 -R /whatever/your/directory/is
Set variable PacketLoss to first digit of percentage of packet loss occurring when pinging host specified by TestIP
PacketLoss=$(ping "$TestIP" -c 2 | grep -Eo "[0-9]+% packet loss" | grep -Eo "^[0-9]")
download file "https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh" and execute it
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
display the filenames which do not have begin with dot
find . -maxdepth 1 -name '[!.]*' -printf 'Name: %16f Size: %6s\n'
Find all *.ogg and *.mp3 (case insensitive) files/directories under your home directory
find $HOME -iname '*.ogg' -o -iname '*.mp3'
Locate file "file1"
find -name file1
Find all .tmp files under and below the /tmp/ directory and remove them
find /tmp -name "*.tmp"| xargs rm
split file abc.txt into pieces per 1500000000 bytes named as "abc.NNN"
split --bytes=1500000000 abc.txt abc
Searches available packages with 'mysql' and 'client' in name.
yum search mysql | grep client
Find all files/directories under current directory tree whose names start with '(test)' followed by two digits and end with '.txt' extension
find . -regex ".*/(test)[0-9][0-9]\.txt"
Recursively removes all empty folders under current folder.
find . -depth -type d -empty -exec rmdir {} \;
Recursively search for all files with names ending with "_test.rb", renaming them to end with "_spec.rb".
find . -name "*_test.rb" | xargs rename s/_test/_spec/
Copy all *.txt files from the current directory tree to /tmp
find . -name '*.txt' | while read line; do echo "Copying '$line' to /tmp"; cp -- "$line" /tmp; done
create directory foo
mkdir -p foo
Counts lines in file file1 and shows progress bar while doing.
bar file1 | wc -l
Recursively prints all files in a current folders, and searches "stringYouWannaFind" in file content ignoring case differences, and preceding found string with its number in file.
find ./ -type f -print -exec grep -n -i "stringYouWannaFind" {} \;
Print first 11 characters from $line, print a tab, print the md5 sum of the file specified by the 13th and onward characters from $line and print a null character at end without a trailing new line
echo -en "${line:0:11}" "\t" $ "\0"
list all files in /home/bozo/projects directory tree that were modified exactly one day ago.
find /home/bozo/projects -mtime 1
Report file system mounted at $path_in_question disk usage if canonical path $path_in_question is a mount point.
df $path_in_question | grep " $path_in_question$"
Find recursively the files named "file" in the current directory ignoring the .git subdirectory
find . -path ./.git -prune -o -name file -print
Print numbered list of all top-level files in the current directory, with name containing 'android'
ls | grep "android" | cat -n
search for all text files in current folder and delete them
xargs rm -f <<< $
ssh into localhost on port 4444
ssh -p 4444 localhost
Make $WEEKS_TO_SAVE+1 directories named "weekly.N" where N ranges from 0 to "$WEEKS_TO_SAVE"
mkdir -p $
Searches manual pages which descriptions contain 'postscript', and prints name and description of only ones that contain any-cased 'png' pattern.
apropos postscript | grep -i png
Compare the contents of "/bin" and "/usr/bin" line by line
diff < <
Counts all business days in a current month.
cal -h | cut -c 4-17 | tail -n +3 | wc -w
Remove files that are less than 1MB in size under current directory
find . -size -1M -exec rm {} \;
Search for 'mystring' in all *.txt files under current directory
find . -name *.txt | xargs egrep mystring
all the files that end with .mp3 and end with .jpg
find . -name '*.mp3' -name '*.jpg' -print
Finds strings with dot-separated sequence of numbers, and prints part of that sequence between the first and second dot.
echo "$f" | grep -Eo '[0-9]+[.]+[0-9]+[.]?[0-9]?' | cut -d. -f2
Search three folders named foo, bar, and baz for all "*.rb" files
find foo bar baz -name "*.rb"
find files which do not have all permissions to all the users in the current directory
find . -type f ! -perm 777 | head
View manual page of the find command
man find
Prints folder path where $mystring file is located.
echo dirname: $
delete all the empty files in the current directory only if they are ok and the user has the permission to delete them
find . -empty -ok rm {}\;
Search in current directory downwards all files whose owner is aa1 or whose name is myfile .
find . \( -user aa1 -o -name myfile \) -print
List all files in the current directory tree that were modified less than 60 minutes ago
find . -mmin -60 |xargs ls -l
Report file systems disk usage using POSIX output format.
df -P
Print a colon-separated list of all directories from the ~/code directory tree, except hidden ones and those below them
find ~/code -name '.*' -prune -o -type f -a -perm /u+x -printf ':%h\n' | sort | uniq | tr -d '\n'
List all files under current directory that are greater than 10000000x512 bytes in size
find . -type f -size +10000000 -print|xargs ls -ld|more
Find all files starting from / whose names end with ".rpm" and change their permissions to 755
find / -name *.rpm -exec chmod 755 '{}' \;
Open all files named 'filename' with 'nano' editor in the entire filesystem
find / -name filename -exec nano '{}' \;
Change permissions to 644 for *.html files under /usr/local
find /usr/local -name "*.html" -type f -exec chmod 644 {} \;
Display the mimetype of "filename"
file -i filename
Perform a default cPanel configuration
find /home/*/public_html/ -type f -iwholename “*/wp-includes/version.php” -exec grep -H “\$wp_version =” {} \;
Change permissions to 600 for all regular .rb files in the current directory tree
find . -name "*.rb" -type f -exec chmod 600 {} \;
List the full path of each directory in the current working directory
tree -dfi -L 1 "$(pwd)"
find all the files in the /usr folder that have been modified after the file /usr/FirstFile.
find /usr -newer /usr/FirstFile -print
find all the files in the /usr folder which have modification date less than or equal to the file "/FirstFile"
find /usr ! -newer /FirstFile -print
recursively change owner of the directory /usr/local to the current user
sudo chown -R `whoami` /usr/local
Stores date of last month day in the 'lastdaymonth' variable.
set lastdaymonth=`cal $month $year |tr -s " " "\n"|tail -1`
Delete all matches to the regex '^.*iframe bla bla bla.*$' in all the php files under current directory tree and modify the files in-place
find ./ -type f -name \*.php -exec sed -i ’s/^.*iframe bla bla bla.*$//g’ {} \;
find all the html files in the current folder which have not been modified in the last 7 days
find . -mtime +7 -name "*.html" -print