nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
concatenates file1.txt, file2.txt, and file3.txt with the filenames printed at the beginning of file contents
head -n99999999 file1.txt file2.txt file3.txt
Find and delete all hard links in the /home directory to file1
find /home -xdev -samefile file1 -print0 | xargs -0 rm
Search for 'Text To Find' in all regular files under current directory tree and show the matched files and matched lines with line numbers
find ./ -type f -exec grep -Hn "Text To Find" {} \;
Find all files under current directory and show their file information
find . -type f | xargs file
Find directory "your/dir" if it is empty
find your/dir -prune -empty -type d
Search the current directory tree for hidden files skipping .htaccess
find . -type f \
Run 'chmod 0644' on all files in the current directory tree
find . -type f -exec chmod 0644 {} \;
Recursively changes group ownership of the $PATH_TO_OUTPUT_FOLDER directory to $GROUP group.
chgrp -R $GROUP $PATH_TO_OUTPUT_FOLDER
Find command will display top 10 Big files from current directory .
find . -type f -exec ls -s {} \; |sort -n -r |head
Find files that are writable by both the “other” and the group under the plsql directory
find plsql -type f -perm -220 -exec ls -l {} \; 2>/dev/null
Find *.js UTF-8 files with BOM and correct them
find . -iname *.js -type f -exec sed 's/^\xEF\xBB\xBF//' -i.bak {} \; -exec rm {}.bak \;
Print the boot time in standard date format
who -b | awk '{$1=""; $2=""; print $0}' | date -f -
Find all files whose names begin with 'Makefile' in the /usr/ports directory tree and count how many of them contain 'QTDIR'
find /usr/ports/ -name Makefile\* -exec grep -l QTDIR '{}' '+' | wc -l
Get the total sizes of all files under current directory
find path -type f -printf '%s\n' | awk '{sum += $1} END {print sum}'
only get md5sum of a file
md5 -q file
find all files in the home folder that are modified in the last 24 hours
find $HOME -mtime -1
find all the files that have been modified exactly 2 days ago
find -mtime 2
Print fourth column of data from text file text.txt where columns separated by one or more whitespaces.
cat text.txt | tr -s ' ' | cut -d ' ' -f4
List all files in entire file system owned by the user wnj and are newer than the file ttt
find / -newer ttt -user wnj -print
find all the text files present in the current directory excluding the search in certain paths.
find . -type f -name "*.txt" ! -path "./Movies/*" ! -path "./Downloads/*" ! -path "./Music/*"
Search regular files under ~/mail for string "Linux"
find ~/mail -type f | xargs grep "Linux"
search for all the symbolic links in a folder and delete them
find /target/dir -type l ! -exec test -e {} \; -exec rm {} \;
find all the html files in the current folder
find . -name "*.html"
Search for files only that end with .php and look for the string $test inside those files
find . -name \*.php -type f -exec grep -Hn '$test' {} \+
Find all regular files in /usr/bin modified less than within the last 10 days
find /usr/bin -type f -mtime -10
Prints all child processes of a process with id 20238, separated with comma.
pstree -p 20238 | sed 's/(/\n(/g' | grep '(' | sed 's/(\(.*\)).*/\1/' | tr "\n" ,
Print a randomly sorted list of numbers from 1 to 10 to file "/tmp/lst" and outputs "-------" followed by the reverse list to the screen
seq 1 10 | sort -R | tee /tmp/lst |cat < < | tac
Write output of "ls -hal /root/" to standard output and to "/root/test.out"
ls -hal /root/ | sudo tee /root/test.out
change the permissions of all the directories in the current folder, print0 is used for handling files with newlines in their file name
find . -type d -print0 | xargs -0 chmod 2775
search for all non empty regular/normal files in the current folder and empty them ie., delete the content not the file
find . -type f -maxdepth 1 -not -empty -print0 | xargs -0i cp /dev/null {}
find files in the current directory having name "filename"
find -iname "filename"
Save host name in variable "thisHOSTNAME"
thisHOSTNAME=`hostname`
Convert all characters in standard input to lower case
sed 's/.*/\L&/'
Make directory "/etc/cron.minute"
mkdir /etc/cron.minute
Print a count of each unique line from standard input
sort | uniq -c
Measure the disk space taken up by all TXT files in the current directory tree
find . -iname "*.txt" -exec du -b {} + | awk '{total += $1} END {print total}'
Find all files under current directory that match the case insensitive regex .\|./.git and replace the text matching the regex '$lower1' with $lower2 in these files
find . -type f \! -iregex '.\|./.git' -exec perl -i -pe 's/$lower1/$lower2/g' {} \;
Find all directories at level 3 of directory tree $from_dir
find $from_dir -mindepth 3 -maxdepth 3 -type d
Print numbers from 1 to 100
seq 1 100
List all regular files under current directory ensuring white space safety
find . -type f -print0 | xargs -0 -n 1
List all files and directories in the current working directory in a long list format sorted by the oldest modification time
ls -alrt `pwd`/*
extract "phantomjs-1.9.0-linux-x86_64.tar.bz2"
sudo tar xvf phantomjs-1.9.0-linux-x86_64.tar.bz2
display all the files having spaces in the current folder
find . -name "filename including space" -print0
Remove the "123_" prefix from all filenames of .txt files in current directory.
find -name "123*.txt" -exec rename 's/^123_//' {} ";"
modify the permissions of all the folders in a directory
find /path/to/dir -type d -exec chmod 755 {} \;
Save the user name in upper case of the current user in variable "v"
v=$(whoami | tr 'a-z' 'A-Z')
Search the current directory tree for regular files whose names end in "log"
find `pwd` -name "*log" -type f
Pushes directory path that saved in $line variable to the dirs stack, expanding symbol '~', if present, as home folder path.
pushd "${line/#\~/$HOME}";
Print paths to all subdirectories inside of a directory
du | awk '{print $2}'
Get directory listing of URL $1 and save them to variable 'header' by deleting '\r' characters
header="$(curl -sI "$1" | tr -d '\r')"
Find all files/directories with space in their names under current directory
find . -name '* *'
Print linker search path using ld formatted on new lines
ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012
change the permissions of all the regular/normal files to 664 in the current folder
find . -type f -exec chmod 664 {} \;
find all the text files in the file system and search only in the disk partition of the root.
find / -mount -name "*.txt"
Find all regular files newer than '/tmp/$$' under '/tmefndr/oravl01' directory tree
find /tmefndr/oravl01 -type f -newer /tmp/$$
List the directory paths of all file.ext files under present working directory
find . -name "file.ext" -execdir pwd ';'
Delete all files under root whose status were changed more than 30 minutes ago
find root -type -f -cmin +30 -delete
Lookup information of the current user
finger `whoami`
Sources script incl.sh in the folder where current running script is located
source "$( dirname "${BASH_SOURCE[0]}" )/incl.sh"
List files in "dir1" that are not in "dir2"
comm -23 < <
Print reverse lookup for IP address 72.51.34.34
dig -x 72.51.34.34
find all the files that have been modified today
find . -type f -mtime 0
Set shell option 'histverify'.
shopt -s histverify
Find all .sh files in the current directory tree and remove them
find . -name "*.sh" -exec rm -rf '{}' \
search for the file test.txt in the folders /home and /opt
find /home /opt -name test.txt
display all the files in the current folder which have been modified in the last 24 hours excluding all directories
find . \ -o \
check if a named screen session already exists
screen -list | awk '{print $1}' | grep -q "$1$"
Print numbers from 1 to 30 with 0 padding to a width of 2
printf " %02d" $
Print $d if $d is an empty directory
find "$d" -prune -empty -type d
Search for 'mystring' in all *.txt files under current directory
find . -name *.txt | xargs egrep mystring
create an archive using 7zhelper.sh as a compress program
tar -I 7zhelper.sh -cf OUTPUT_FILE.tar.7z paths_to_archive
Save the 10 ping results to "$gateway" in variable "pingResults"
local pingResults=$
Recursively change the owner of npm's directories to the current user
sudo chown -R $ $/{lib/node_modules,bin,share}
Find all symbolic links in the current working directory that link to files outside the current working directory
find . -type l -exec sh -c 'echo $ "<-- {}"' \; | grep -v "^$"
Print "Total generated: " followed by the number of unique lines in "$generated_ports"
echo "Total generated: $."
Find all files under current directory that match the case insensitive regex .\|./.git and replace all occurrences of the regex $1 with $upper2 in these files
find . -type f \! -iregex '.\|./.git' -exec perl -i -pe 's/$1/$upper2/gi' {} \;
find all directories in the current directory
find . -type d
Create directory `junk' in the home directory
find ~ -type d -exec mkdir junk {} \; 2> /dev/null
Counts total lines in all *.php files in the current directory recursively
find . -name '*.php' -type f | xargs cat | wc -l
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 d -printf ':%p'
Run "ps -elfc" followed by "ls" on host "example.com"
ssh example.com "ps -elfc; ls"
Find all directories in current directory without going into sub-directories
find . -type d -maxdepth 1
search for all the directories in the current folder and run the print command in the searched folder
find . -type d -execdir sh -c 'printf "%s/%s\n" "$PWD" "$0"' {} \;
Construction with additional '-exec true' to be used if both commands need to run regardless of their success or failure.
find . -name "*.txt" \( -exec echo {} \; -o -exec true \; \) -exec grep banana {} \;
List all files/directories under current directory matching the posix-egrep type regex ".+\.(c|cpp|h)$" in their names excluding the files that contain 'generated' or 'deploy' in their paths
find . -regextype posix-egrep -regex '.+\.(c|cpp|h)$' -print0 | grep -vzZ generated | grep -vzZ deploy | xargs -0 ls -1Ld
Set permissions of all files under "/opt/lampp/htdocs" to 644
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
find all the php files in current folder using regular expressions
find . -regex '.+\.php'
Recursively removes all empty folders under current folder.
find -depth -type d -empty -exec rmdir {} \;
List all regular files in the current directory tree
find . -type f | xargs ls -l
Find all .sh files in the current directory tree and remove them
find . -name "*.sh"| xargs rm -rf
Search all files called "abc" that reside in the current directory tree for string "xyz"
find . -name "abc" -exec grep "xyz" {} \;
Find all files that contain the case insensitive regex 'stringtofind' in maximum 1 level down the / directory without descending into other partitions
find / -maxdepth 1 -xdev -type f -print -exec grep -i "stringtofind" -q {} \;
find all the text files in the current folder and display their Permissions and size along with their name
find . -name "*.txt" -printf "%M %f \t %s bytes \t%y\n"
Split "database.sql" into files of at most 100000 lines each with prefix "database-"
split -l 100000 database.sql database-
search for all the files in a directory and give the first five characters of the file
find . -type f -exec bash -c 'echo ${1:0:5}' funcname {} \;
find all 'js' suffix files exclue the path *exclude/this/dir*' under current dirctory
find . -name '*.js' -not -path '*exclude/this/dir*'
Find files with 002 permission in entire file system
find / -type f -perm -002
Join colon-separated information in 3 files LN.txt PH.txt and AD.txt in a cascade fashion: join LN.txt and PH.txt, then join the result with AD.txt
join -t':' <(sort LN.txt) <(sort PH.txt) | join -t':' - <(sort AD.txt)
Search the current directory tree for files matching regular expression '.*myfile[0-9][0-9]?'
find . -regex '.*myfile[0-9][0-9]?'
search for all the regular/normal files with the name "access.log" in the folder /var/www which are bigger than 100MB
find /var/www -type f -name «access.log*» -size +100M