nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
create a sub shell and search for regular/normal file with the name "myfile" in the entire file system and discard all the errors
sh -c "find / -name myfile -type f -print 2> /dev/null"
Convert "abc" to a string of hexadecimal bytes
echo abc | od -A n -v -t x1 | tr -d ' \n'
find all the directories in the file system which begin with "man"
find / -type d -name 'man*' -print
Display hardware platform, ie. x86_64 even if current kernel uses 32-bit addressing.
uname -i
Delete all empty directories in the current directory tree
find -type d -empty -exec rmdir -vp --ignore-fail-on-non-empty {} +
search for the file "myfile" in the current folder and display all errors apart from permission denied error
find . -name myfile |& grep -v 'Permission denied'
Remount "/home/evgeny" with the "suid" flag set
sudo mount -i -o remount,suid /home/evgeny
Delete all files not owned by valid users
find / -nouser | xargs -0 rm
Search the files in the current directory tree for lines containing string "vds admin"
find . -exec grep -i "vds admin" {} \;
Search the current directory tree for files and directories whose names do not end in "exe" and "dll"
find . | grep -v '$'
search for all regular/normal files in current folder and display all the files which contain 16 lines
find . -type f -print0 | xargs -0 grep -cH '.' | grep ':16$'
search for files which are writable by either their owner or their group
find . -perm /u=w,g=w
Open executable file for command "rails" in text editor "mate"
mate `which rails`
Get the actual find exectuable path
which find
Create ssh tunnel through "genja.org" connecting localhost port 4444 to "raptor.lan" port 22
ssh -L 4444:raptor.lan:22 genja.org
Find CSS files omitting results containing "CVS"
find . \! -path "*CVS*" -type f -name "*.css"
kill all background jobs
jobs -p | xargs kill
Push the directory containing the first existing command found in all arguments to the directory stack.
pushd $
Change to the directory containing the "oracle" executable
cd "$(dirname "$")"
display all the directories in the folder /usr/share
find /usr/share -type d
Find file names *blast* in specfied directory, case insensitive
find /usr/local -iname "*blast*"
Search for 'some string' in all *js files under current directory and show the matched lines with line numbers
find . -name '*js' -exec grep -n 'some string' {} \;
show processes for all users, their user/owner, and those not attached to a terminal
ps aux
Find all the SUID files in the current directory tree
find . -perm /u=s
Find all files in the /etc folder that have been modified within the last 30 days and copy them to /a/path/.
find /etc/ -mtime -30 | xargs -0 cp /a/path
Find all files/directories named 'foo' under current directory tree without descending into directories named 'foo'
find . -name foo -type d -prune -o -name foo
Search the current directory tree for all files matching either pattern "*.rb" or pattern "*.py"
find . -name "*.rb" -or -name "*.py"
Search the home directory tree for .tar.gz files newer than file "filename"
find ~/ -name *.tar.gz -newer filename
Search the current directory tree for regular files that can be read by noone
find -type f ! -perm -444
Compress $file file using gzip
gzip "$file"
Save the number of bytes in "$file" after decompression into variable "size"
size="$(zcat "$file" | wc -c)"
Find all regular files under '/directory_path' directory tree that have been modified within the last day
find /directory_path -type f -mtime -1 -print
Find all files in the current directory tree, except GIT files
find -type f -name .git -prune -o -print
Saves exit statuses of piped commands in a system variable PIPESTATUS=''
true | false | true
display a long listing of all the files in the /var folder which are bigger than 10MB. print0 is used to handle the files which have new lines in their names
find /var -size +10000k -print0 | xargs -0 ls -lSh
Prints long listing of directories "./my dir" and "./anotherdir" sorted from oldest to newest, with appended indicators.
$ ls -Fltr "./my dir" "./anotherdir"
Make directory "/cpuset"
mkdir /cpuset
search for all the perl files in the folder /nas/projects/mgmt/scripts/perl which have been modified 8-10 days ago.
find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl"
Print a sorted list of the extensions of the regular files from the current directory tree matching pattern '*.???'
find . -type f -name "*.???" | awk -F. '{print $NF}' | sort -u
find all the "passwd" files in the entire file system
find / -iname passwd
Find all files that belongs to user Tecmint under /home directory
find /home -user tecmint
Find all files under dir and calculate their md5sum and save the output to dir.md5
find dir -type f -exec md5sum {} + > dir.md5
Continuously send "ok" plus newline to the program "recalcitrant.php"
yes ok | recalcitrant.php
Find files that have been modified within the last month and copy them somewhere
find /etc/ -mtime -30 | xargs -0 cp /a/path
Find file names *blast* in specfied directory
find /usr/local -name "*blast*"
Find all directories named 'files' under current directory and set read-write-execute permission for owner and group and no permission for other for those directories
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
Find all files under current directory and append a null character at the end of each of their paths
find -type f -print0
Replace all instances of ";" with "\n" in "[email protected];[email protected]"
echo "[email protected];[email protected]" | sed -e 's/;/\n/g'
Search directories called ' backup ' from /usr directory downwards and print them.
find /usr -type d -name backup -print
List the directory paths of all file.ext files under present working directory
find . -name "file.ext" -execdir pwd ';'
Copy *.txt files from the dir/ directory tree along with their parent directories
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ --parents
Find all files/directories under minimum 1 level down the $FOLDER directory and sort them
find "$FOLDER" -mindepth 1 | sort
Find and kill a process by name
kill $
Search all Python files in the current directory tree for string "import antigravity"
find . -name "*.py" | xargs grep 'import antigravity'
Archive "./dir" to "user@host:/path" via ssh on port 2222 and display progress
rsync -rvz -e 'ssh -p 2222' --progress ./dir user@host:/path
Delete all regular files that have not been modified in the last 31 days under '/path/to/junk/files' directory tree
find /path/to/junk/files -type f -mtime +31 -exec rm -f {} \;
Search the current directory for files whose names start with my
find . -name 'my*'
Find all *.txt files of user root under / directory and show a few lines of output from the beginning
find / -user root -iname "*.txt" | head
Copy a large sparse file "sparse-1" to "sparse-1-copy"
rsync --sparse sparse-1 sparse-1-copy
Print a list of all duplicate filenames in the current directory tree if there is no white space in filenames
find . |sed 's,\/\$,\1/\2\t\1/\L\2,'|sort|uniq -D -f 1|cut -f 1
Find all files/directories that start with 'screen' in their names under user's home directory tree
find ~ -iname "screen*"
Removes all files from current folder but 5 newest ones, filtering out directories from initial search.
ls -tp | grep -v '/$' | tail -n +6 | xargs -d '\n' rm --
Print git branch currently checked out in a working directory.
git status | grep "On branch" | cut -c 11-
Find all 100MB+ files and delete them
find / -size +100M -exec rm -rf {} \;
Print the IP addresses for the current host name
hostname -I | awk -F" " '{print $1}'
Locate all *.csv files under the current directory tree separating the file names with zeroes
find . -name "*.csv" -print0
Gets IP address of 'en1' network interface.
ifconfig en1 | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p'
Change permissions to 644 for all files showing the respective chmod command
find ./ -type f -print0 | xargs -t -0 chmod -v 644
Decompresses file 'xac.bz2', redirecting output to standard out.
bzip2 -dc xac.bz2
Report file system containing path to the current working directory disk usage in kilobytes.
df -k .
Sort ":" delimited lines in "test.txt" by the first and third field preserving only unique lines
sort -u -t : -k 1,1 -k 3,3 test.txt
Merge colon-separated information from file1 and file2 where second field of both files matches, sorting the result based on this field - for each line, output: first 3 fields of first file, followed by first 3 fields of second file.
join -o 1.1,1.2,1.3,2.1,2.2,2.3 -j2 <(sort -k2 file1) <(sort -k2 file2)
Search PATH for utilities called "rename", display the type of file for each match found.
which -a rename | xargs file -L
Calculate md5 sum of the md5 sum of all the sorted files under $path
find "$path" -type f -print0 | sort -z | xargs -r0 md5sum | md5sum
Find all .sh files in the current directory tree and remove them
find . -name "*.sh" -print0 | xargs -0 rm -rf
display files ending with ".ext" in current folder which are present in the file "foo"
find . -type f -name \*.ext | xargs grep foo
Find all files under current directory that were modified in the last 24 hours and also include the files that were modified in less than 1 day ago
find -daystart -mtime +0
Find all regular files that reside in the current directory tree and were last modified more than 3 days ago
find . -type f -mtime +3
List each subdirectory name composing the current working directory
pwd | cut -b2- | tr '/' '\n'
Counts number of lines returned by curl request.
curl yahoo.com --silent | wc -l
Display name and value of 'variable' if it exists.
env | grep '^variable='
search for regular/normal file with the name "myfile" in the entire file system and discard all the errors
find / -name myfile -type f -print 2> /dev/null
List all files in maximum 2 levels down the current directory
find . -maxdepth 2 -type f -exec ls -l {} \;
find all the files in the current folder that have been modified exactly 24*3 hours ago
find ./ -mtime 3
Execute "lynx -dump http://dslrouter/stats.html" every 10 seconds
watch --interval=10 lynx -dump http://dslrouter/stats.html
Find all symbolic links containing 'javaplugin' in their names under '/usr' directory tree
find /usr/ -lname *javaplugin*
Recursively change the group of all files in "/tmp/php_session" to "daemon"
chown -R :daemon /tmp/php_session
Search for filenames matching "android" in the current directory and number the output
ls | grep android | nl
Search for the case insensitive regex expanded by $2 in all files named $1 (to be expanded) under current directory
find . -name $1 -type f -exec grep -i $2 '{}' \;
Show all running processes with name matching "postgres"
ps aux | grep postgres
Display numbers of processes in following states: running, sleeping, stopped, and defunct .
top -bn1 | grep zombie | awk '{print $4" "$6" "$8" "$10}'
Save number of lines in 'file.txt' file in 'nbLines' variable
nbLines=$(cat -n file.txt | tail -n 1 | cut -f1 | xargs)
Find all directories in the /path/to/base/dir tree
find /path/to/base/dir -type d
Filters unique lines by matching against the first column of a .csv file
tac a.csv | sort -u -t, -r -k1,1 |tac
print all files in the directories except the ./src/emacs directory
find . -wholename './src/emacs' -prune -o -print
find all empty files in home directory
find ~ -empty
find all the perl files in the current folder and search for a pattern
find . -name '*.pl' | xargs grep -L '^use strict'
Find all *.java files under current directory and change their encoding to utf-8 from cp1252
find . -type f -name '*.java' -exec sh -c 'iconv -f cp1252 -t utf-8 "$1" > converted && mv converted "$1"' -- {} \;
find all files that have been modified yesterday
find /some/dir -mmin -$((currtime + )) -a -mmin +$()
For each line whose first field is the same in file1 and file2, output the common first field followed by all other fields in file1 and file2.
join -j1 file2 file1