nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Counts total line number of all *.php file in a current folder and subfolders.
cat `/gnuwin32/bin/find.exe . -name *.php` | wc -l
prints the last non-empty line of a file
tac $FILE | grep -m 1 '.'
Search for 'example' in all regular files under current directory tree and also print the filenames
find . -type f -exec grep "example" '{}' \; -print
Wrap each line in "yourfile" to fit in 79 characters and right pad any lines shorter with spaces
fold -w79 yourfile | sed -e :a -e 's/^.\{0,78\}$/& /;ta'
Print a minimal set of differences between files in directories "a" and "b", ignore the first 3 lines of output, and print any line starting with "-" with the first character removed
diff -dbU0 a b | tail -n +4 | grep ^- | cut -c2-
display all the empty files in the current folder
find . -empty
Lists content of compressed text file.
zless MyFile
Replace all occurrence of "subdomainA.example.com" with "subdomainB.example.com" in all files under /home/www and below
find /home/www/ -type f -exec sed -i 's/subdomainA\.example.com/subdomainB.example.com/g' {} +
Search the entire file hierarchy for files ending in '.old' and delete them.
find / -name "*.old" -delete
Change permissions to 644 for all regular files under the /path/to/dir/ tree unless these permissions are already set
find /path/to/dir ! -perm 0644 -exec chmod 0644 {} \;
display all the files in the current folder
find .
Find all .js files in the $d directory tree whose pathnames do not contain whitespaces
find $d -name '*.js' | grep -v " "
Exclude directory from find . command
find . -name '*.js' | grep -v excludeddir
Print the IP address of your SSH session
who am i|awk '{ print $5}'
Print the list of files changed within the last minute
find / -newerct '1 minute ago' -print
Search for 'string-to-find' in all files under current directory tree matching the regex 'filename-regex.\*\.html' in their paths and show the matched lines along with the filenames
find . -regex filename-regex.\*\.html -exec grep -H string-to-find {} \;
Find all *.rb files under current directory and print them on stdout putting the file name/path in-between two string literals 'Hello,' and '!'
find . -name "*.rb" -type f | xargs -I {} echo Hello, {} !
Save the directory of the full path to the current script in variable "dir"
dir=$(dirname $)
List all *.c files in entire file system
find / \! -name "*.c" -print
Assign the alias rm5g to a find command that removes any .tar file larger than 5 gigabytes.
alias rm5g="find / -type f -name *.tar -size +5G -exec rm -i {} \;"
Calculate the md5 sum of "submission.cpp" with less sensitivity to superficial changes like comments or whitespace
cat submission.cpp | astyle -bj | cpp - | md5sum
Search for 'mystring' in all *.txt files under current directory
find . -name "*.txt" -exec egrep mystring {} \;
find all the files that have been changed exactly 24 hours ago
find . -ctime 1 -type f
Returns exit code 1.
false
Search the .log files in the current directory tree for string "The SAS System"
find `pwd` -name "*.log" -exec grep "The SAS System" {} \;
Display differences between files dir1.txt and dir2.txt.
diff dir1.txt dir2.txt
List all *.txt files/directories under /etc
find /etc -name "*.txt" -exec ls -l {} \;
display the commands to force delete all jpg files in current directory which are less than 50KB and do not search in the sub directories
find . -maxdepth 1 -name "*.jpg" -size -50k | xargs echo rm -f
SSH into "hostname" on port 22 as user "myName"
ssh -p 22 myName@hostname
Find all .txt files in the current directory tree on a BSD system and edit them with `vim'
find . -name "*.txt" | xargs -o vim
Measure the disk space taken up by all *.txt files in directory trees folder1 and folder2
find folder1 folder2 -iname '*.txt' -print0 | du --files0-from - -c -s | tail -1
Print a detailed list of all regular files from the current directory tree
find . -type f -ls
Search directory tree `foo' for files named `Headers'
find foo -name Headers
Print the current shell
ps -p $$ | tail -1 | awk '{print $NF}'
Compress every file in the current directory tree with gzip and keep file extensions the same
find folder -type f -exec gzip -9 {} \; -exec mv {}.gz {} \;
List all files/directories under $dir_name with size $sizeFile and print them according to the format string '%M %n %u %g %s %Tb %Td %Tk:%TM %p\n'
find $dir_name -size $sizeFile -printf '%M %n %u %g %s %Tb %Td %Tk:%TM %p\n'
Find files/directories that belong to user 'ian' under '/tmp' directory tree
find /tmp -user ian
Display a dump of "file" as floating point values of double size
od -t fD file
Split "file.txt" into files of at most 1 MiB in size with a numeric suffix and prefix "file"
split -b 1M -d file.txt file
remove all the files with the name "Trash" in the folder /home
find /home -name Trash -exec rm {} \;
Read a single character from standard input with prompt "Is this a good question (y/n)? " and timeout of 3 seconds and save the response to variable "answer"
read -t 3 -n 1 -p "Is this a good question (y/n)? " answer
Print command line of process with pid 17709
cat /proc/17709/cmdline | xargs -0 echo
Go to directory named "~"
cd `echo -n "~"`
Find all files under current directory that match the case insensitive regex .\|./.git and replace the text matching the case insensitive regex expanded by $1 with $upper2 in these files
find . -type f \! -iregex '.\|./.git' -exec perl -i'' -pe "s/$1/$upper2/gi" {} +
Find all files and directories in the current directory tree with "linkin park" in their names and copy them to /Users/tommye/Desktop/LP
find . -iname "*linkin park*" -exec cp -r {} /Users/tommye/Desktop/LP \;
Find all *FooBar* files/directories under current directory and copy them to ~/foo/bar
find . -name '*FoooBar*' | sed 's/.*/"&"/' | xargs cp ~/foo/bar
Count the number of files in the directory trees whose pathnames match pattern '/dev/sd*[a-z]'
find /dev/sd*[a-z] -printf . | wc -c
search for the file "file_name" in the folder /path
find /path -name file_name
bind word "foobar" to key code "\e[24~"
bind '"\e[24~":"foobar"'
Pass numbers 1 to 100000 as arguments to "/bin/true"
/bin/true $
Print all lines from the last occurrence of the regex 'pattern' to the end of the file 'file'
tac file | awk '/pattern/{print;exit}1' | tac
Prints total number of lines of all *.c files in a current folder and subfolders.
find . -name '*.c' -print0 |xargs -0 wc -l|grep -v total|awk '{ sum += $1; } END { print "SUM: " sum; }'
find all the directories with the name "some-dir" in the current folder and move them to another folder and do not search in subfolders
find ./ -maxdepth 1 -name "some-dir" -type d -print0 | xargs -0r mv -t x/
Prints folder where current script is located
echo "dirname: `dirname $0`"
Scan every file in /etc for IPV4 addresses.
find /etc -exec grep '[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*' {} \;
Search the src/ directory recursively for .c and .h files
find src/ -name '*.[ch]'
Set permissions to ug=rwx,o= for directories under the $d directory tree
find $d -type d -exec chmod ug=rwx,o= '{}' \;
Find the 5 largest regular files in the current directory and below.
find -type f -exec du -Sh {} + | sort -rh | head -n 5
search for a directory in a folder taking name as argument and assign the first instance of it to a variable
DIR='find $HOME -type d -name $1 | head 1'
Delete all files in the TBD directory that were modified more than 1 day ago
find /TBD/* -mtime +1 | xargs rm -rf
Print the line with most consecutive repeats prefixed with its count from standard input
uniq -c | sort -n | tail -n1
Find all files under current directory with their size and paths, reverse sort them numerically, then print the 2nd field (with space as the delimiter) of the first 4 entries
find -type f -printf "%s %p\n" | sort -nr | head -n 4 | cut -d ' ' -f 2
search for all the mp3 files in the current folder and change the character encoding of them to EUR-KR
$ find . -name "*mp3" -print0 | xargs -0 mid3iconv -e EUR-KR -d
Find all files named "foo_bar" in the current directory recursively
find -name foo_bar
find all the files in the current folder which have the name net or comm in them
find . -regex '.*\(net\|comm\).*'
Find and show all files in the current directory tree that are exactly 2000 kB
find . -size 2000k
display all files in the current folder which do not match the regular expression
find . -not -regex ".*test.*"
Show the list of user wnj's files that are newer than file `ttt'
find / -newer ttt -user wnj -print
Delete all files in directory $DIR that have not been accessed in at least 5 days
find "$DIR" -type f -atime +5 -exec rm {} \;
Search for all files and directories named foo, FOO, or any other combination of uppercase and lowercase characters beneath the current directory.
find . -iname foo
Format "input" as alternating rows in a table
| paste - - - | column -s' ' -t
Remove all regular files from the current directory tree whose names do not end with "txt"
find . -type f -not -name '*txt' -print0 | xargs -0 rm --
Remove trailing spaces from all files under current directory ignoring directories wtih *.git* in their paths
find . -type f -not -iwholename '*.git*' -print0 | xargs -0 perl -pi -e 's/ +$//'
Find files/directories under '/dir' directory tree that are newer than 'yesterday.ref' file and older than 'today.ref' file by modification time
find /dir -newer yesterday.ref -a \! -newer today.ref -print
Print numbers from 1 to 10 with 2 values per line
seq 10 | sed '2~2G' | awk -v RS='' '{$1=$1; print}'
Find all empty directories under /tmp
find /tmp -type d -empty
Connect to host "$USER_AT_HOST" in master mode in the background without executing any commands and set the ControlPath to "$SSHSOCKET"
ssh -M -f -N -o ControlPath="$SSHSOCKET" "$USER_AT_HOST"
Find all *foo files/directories under current directory
find . name *foo
find all the files in the entire file system which belong to the user "roger"
find / -user roger -print
find all log files larger then 100MB in /home directory and delete them .
find /home -type f -name *.log -size +100M -exec rm -f {} \;
Find all files/directories under 'A' directory tree excluding the paths containing the directory 'a'
find A \! -path "A/a/*"
find the top 25 files in the current directory and its subdirectories
find . -type f -exec ls -al {} \; | sort -nr -k5 | head -n 25
Find all files recursively starting from / that have been modified in the past 30 minutes and list them
find / -mmin -30 -ls
Copy all directories recursively from "source/" to "destination/" excluding all files
rsync -a --include='*/' --exclude='*' source/ destination/
Find the passwd file under root and two levels down
find / -maxdepth 3 -name passwd
Uncompress "archive.tar.gz" and extract the archive to "/destination"
gzip -dc archive.tar.gz | tar -xf - -C /destination
search for a file "file" in current folder and if the file is found quit !
find -name file -quit
Execute 'echo -e "\033[31mHello World\033[0m"' every without color support 2 seconds
watch 'echo -e "\033[31mHello World\033[0m"'
Find all files/directories that belong to the group 'accts' under '/apps' directory tree
find /apps -group accts -print
Change directory to the alphabetically last path under the current directory
cd "$"
display all regular files in current folder which have spaces in their name
find -type f -name "* *"
Lists all files in a current folder, separating names with space.
ls -1 | awk 'ORS=" "'
search for all the directories in a folder and limit the search to current folder and give them as input to the python script
script.py $
Create symbolic links in the current directory for all files excluding "CONFIGFILE" located in "/your/project"
find /your/project -maxdepth 1 ! -name "CONFIGFILE" -exec ln -s \{\} ./ \;
Search for all zero-byte files and move them to the /tmp/zerobyte folder
find test -type f -size 0 -exec mv {} /tmp/zerobyte \;
Search directory tree $DIR for *.txt files
find $DIR -name "*.txt"
Find grub.conf files in entire file system
find / -name grub.conf
Save the current working directory and the directory name of the current script to variable "DIR"
DIR=`pwd`/`dirname $0`
Calculate md5 sum of files $source_file and $dest_file
md5sum "$source_file" "$dest_file"
Display the 'bash' manpage, going to the first occurence of \' sequence of characters.
man bash | less -Ip "\\\'"