nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Append "<br/>" to the end of each line in "1\n2\n3"
echo -e "1\n2\n3" | sed 's/.*$/&<br\/>/'
Recursively copies everything under the 'current' folder to the '.hiddendir' folder.
cp * .hiddendir -R
find all the symbolic links in the current folder and follow to the original file
find -L . -type l
insert "e" when it's pressed
bind '"e":self-insert'
Find recursively the files named "file" in the current directory ignoring the .git subdirectory
find . -path ./.git -prune -o -name file -print
Find all files/directories named 'photo?.jpg' under current directory tree
find . -name photo\?.jpg
find all the links in the root folder which point to nothing and display them.
find / -type l -print | perl -nle '-e || print';
List all files in maximum 2 levels down the current directory
find . -maxdepth 2 -type f -print0 | xargs -0 -n1 ls -l
Display "infile" as printable characters or backslash escapes
cat infile | od -c
search in root ( / ) directory downwards all files which have less than 2 links.
find / -links -2 -print
Move all files from the `sourceDir' directory to the `destDir' directory
find sourceDir -mindepth 1 -maxdepth 1 -exec mv --target-directory=destDir '{}' +
Assign the alias rm1g to a find command that removes any .tar file larger than a gigabyte.
alias rm1g="find / -type f -name *.tar -size +1G -exec rm -i {} \;"
search for a specific word in all files beginning with a specific word in the current directory
find . -name "file_*" -follow -type f -print0 | xargs -0 zcat | agrep -dEOE 'grep'
File 'mydatafile' has a number on each line, display the sum of these numbers.
awk '{s+=$1} END {print s}' mydatafile
Prints long listing of "$dir/$file" file.
ls -l -- "$dir/$file"
create a soft link of the files in the folder /media/movies which have been modified in the last 30 days
find /media/Movies -type f -mtime -30 -exec ln -s {} /media/Movies/New/ \;
Reports count of characters in the value of ${FOO} variable as follows: "length(FOO)==<counted number of characters>"
echo -e "length(FOO)==$(echo -ne "${FOO}" | wc -m)"
Search for utility "foo" in PATH, display its file type description.
file $(which foo)
Search for .zip files that are larger than 100M found anywhere in the file system and delete those files.
find / -type f -name *.zip -size +100M -exec rm -i {} \;
List files larger than 10MB under /var/log /tmp that haven't changed in a month
find /tmp /var/tmp -size +30M -mtime 31 -print0 | xargs -0 ls -l
Find all files in the /var/tmp directory tree with uid=1000
find /var/tmp -uid 1000
Find recursively the latest modified file in the current directory
find . -type f | sed 's/.*/"&"/' | xargs ls -E | awk '{ print $6," ",$7 }' | sort | tail -1
Find all files under ./lib/app and sort them
find ./lib/app -type f | sort
Search for all *.ogg files in the $HOME directory that have an access time of greater than 30 days
find $HOME -iname '*.ogg' -atime +30
Print "Cannot acquire lock - already locked by " followed by content of $lockfile file
echo "Cannot acquire lock - already locked by $"
Find files in the current directory tree that have one link
find . -links 1
Read a line of standard input into variable "_command" with the prompt as the current working directory followed by "$"
read -p "`pwd -P`\$ " _command
Send SIGTERM signal to all python processes running script "csp_build.py"
kill $
find all the ".flac" files in the current folder and create a sub shell and convert these to mp3 with 128k bit rate
find -name "*.flac" -exec bash -c 'ffmpeg -i "{}" -y -acodec libmp3lame -ab 128k "${0/.flac}.mp3"' {} \;
Search all regular files in the current directory tree for "example"
find -type f -print0 | xargs -r0 grep -F 'example'
find files changed in the last 1 day
find . -mtime -1 -type f
Show the value of variable "list", discarding consecutive duplicates and adding number of occurrences at the beginning of each line.
echo "$list" | uniq -c
Execute /usr/bin/find with $* arguments
/usr/bin/find $*
Rename "svnlog.py" to "svnlog"
mv svnlog.py svnlog
Find all directories under /path/to/base/dir and change their permission to 755
find /path/to/base/dir -type d -exec chmod 755 {} +
Remove empty directories from directory tree /srv/abc
find /srv/abc/ -type d -empty -exec rmdir {} \;
Find all directories under current directory and set read-write-execute permission for owner, read-execute permission for group and other for those directories
find . -type d -exec chmod u=rwx,g=rx,o=rx {} \;
Display the contents of "file" formatted into a table, removing duplicate lines where the first 12 characters are duplicates, and display the number of occurrences at the beginning of each line.
column -t file | uniq -w12 -c
Find files in the current directory and below that are less than 500 kB in size
find . -size -500k -print
Calculate the md5 sum of all the file metadata in the current directory tree excluding ".svn"
find . -name '.svn' -prune -o -type f -printf '%m%c%p' | md5sum
Add directory "$HOME/Pictures" to the directory stack
pushd "$HOME/Pictures"
Print the file system disk space usage for "/dev/disk0s2" if exists
df | grep /dev/disk0s2
find the oldest normal file in the current directory and display with its timestamp
find ! -type d -printf "%T@ %p\n" | sort -n | head -n1
Find all the files that end with the extension “.java” in the current directoy tree
find . -name "*.java"
Print the terminal file of the users who are logged in with "admin" in their name
who |grep -i admin |cut -c10-20
Mount "proc" file system on "/var/snmp3/proc"
mount -t proc none /var/snmp3/proc
Search in the current directory and all sub-directories except ./D for the file named hi.dat
find -path ./D -prune -o -name hi.dat -print
Removes files that are listed in file 'xaa'.
rm $
Count the occurrence of 2 in the string '1 1 2 2 2 5'
echo "1 1 2 2 2 5" | tr ' ' $'\n' | grep -c 2
reverse both words and lines in file
tac filename | awk '{for printf; printf}'
find all the file which name (name can contains space) end with c or h and content contain 'thing'
find . -name '*.[ch]' -print0 | xargs -r -0 grep -l thing
Find files starting with the word "file" in the current directory tree, ignoring the case
find . -iname "file*"
display all directories in current folder
find . -type d -print0
Search the current directory, except the subdirectory tree ".svn", for files whose name is "foo.cpp"
find . -name 'foo.cpp' '!' -path '.svn'
Remove all files under /myfiles that were accessed more than 30 days ago
find /myfiles -atime +30 -exec rm {} \;
Find all files whose names do not begin with "zsh" on ext3 file systems
find / -fstype ext3 -name zsh*
Filters out strings, using the extended regexp pattern '^#|^$|no crontab for|cannot use this program' from "$USERTAB"
echo "$USERTAB"| grep -vE '^#|^$|no crontab for|cannot use this program'
search for text files in the folder /home/you which have been modified in the last 60*24 hours(case insensitive search) and display their contents
find /home/you -iname "*.txt" -mtime -60 -exec cat {} \;
delete recursively, without prompting, any files or directories under the current directory that case insensitively match the filename ".svn"
find . -iname .svn -exec rm -rf {} \;
List all existing environment variables in the current shell.
env | awk -F= '/[a-zA-Z_][a-zA-Z_0-9]*=/ { if (!system("[ -n \"${" $1 "+y}\" ]")) print $1 }' | sort | uniq
Change directory to the real path of the directory containing the current script
cd $(readlink -f $(dirname $0))
Lists all files in a current folder, separating names with 'some_delimiter'.
ls -1 | perl -pe 's/\n$/some_delimiter/'
Locate files that reside in the /u/bill directory tree and were last accessed between 2 and 6 minutes ago
find /u/bill -amin +2 -amin -6
Find *.java files in the current directory with GNU find and replace foo with bar in those files
find . -name "*.java" -exec sed -i s/foo/bar/g \;
Search the current directory tree for regular files whose names begin with "orapw"
find . -name "orapw*" -type f
find all the directories in the current folder and change to these directories and run a command
find . -type d -exec sh -c 'cd -P -- "{}" && pwd -P' \;
find all the configuration or text files in current directory
find . -type f \( -name "*.conf" -or -name "*.txt" \) -print
find regular file named foo.txt under root / directory.
find / -name foo.txt -type f -print
Find all .zip files starting from the current directory which are owned by user tommye
find . -type f -user tommye -iname "*.zip"
Find all *.p[lm] files/directories under current directory
find -name '*.p[lm]'
Split a file "file.tar.gz" into pieces with size 1024 MB
split -b 1024m file.tar.gz
Find files/directories that are newer than 'foo.txt' under current directory tree
find -newer foo.txt
Search the current directory recursively for files whose size is between 10 and 50 MB
find . -size +10M -size -50M -print
find all the normal/regular files in the current directory and search for the word mail and display the file names
find . -type f -exec grep -il mail
display a long list of the files in the current folder which have the word fuddel in all the files in the current folder and then search for the word fiddel in the previously matched files
find -exec grep -q fuddel {} ";" -exec grep -q fiddel {} ";" -ls
search for the regulars file starting with HSTD which have been modified yesterday from day start and copy them to /path/tonew/dir
find . -type f -iname ‘HSTD*’ -daystart -mtime 1 -exec cp {} /path/to new/dir/ \;
display the contents of all java script files in a folder and save the output to a file
find src/js -type f -name "*.js" -exec cat {} >> ${jsbuild}$@ \;
Print only the number of lines in file "$f"
wc -l $f | tr -s ' ' | cut -d ' ' -f 1
Find all files which begin with 'a' or 'b' from current directory downwards and print them.
find . -name [ab]* -print
Set up a local SSH tunnel from port 80 to port 3000
ssh $USERNAME@localhost -L 80:localhost:3000 -N
Show system information: kernel name, hostname, kernel release and version, machine architecture, processor type, hardware platform, and operating system type.
uname -a
Execute "date" every second
watch -n 1 date
Find files/directories under /tmp smaller than 100 bytes
find /tmp -size -100c
find all the symbolic links in the current folder that are broken
find . -xtype l
Search /usr, /home, /tmp for *.jar files
find /usr /home /tmp -name "*.jar"
set alias "restart_rails" for command 'kill -9 `cat tmp/pids/server.pid`; rails server -d'
alias restart_rails='kill -9 `cat tmp/pids/server.pid`; rails server -d'
Print each line in "file1" and file2" separated by a space
paste -d'¤' file1 file2 | sed 's,¤, ,g'
Report total disk usage info on root file system, printing all sizes as power of 1000
df -H --total /
Archive "/media/Incoming/music/" to "/media/10001/music/" on host "server" and skip files that are newer in the destination, delete any files in the destination not in the source, and compress data during transmission
rsync -avzru --delete-excluded /media/Incoming/music/ server:/media/10001/music/
find all the normal/regular files in the current folder which have been modified two days ago and display a long listing of them
find . -type f -mtime 2 -mtime -3 -daystart -exec ls -l {} \;
find files with the extension .conf in the /etc directory
find /etc -name '*.conf'
Find all 777 permission directories under current directory and set permissions to 755
find . -type d -perm 777 -print -exec chmod 755 {} \;
Search the current directory tree for files that are less than 50kb
find . -size -50k
Prints the size in kb of the first 100 lines of a file
echo `cat $FILE | head -n 100 | wc -c` / 1024 | bc -l
Print the last 10 lines of '/var/log/syslog', printing out any additional data appended to the file
tail -f /var/log/syslog
Delete all but the most recent X files in bash
|sort|uniq -u|xargs rm
Find the password file between sub-directory level 2 and 4.
find -mindepth 3 -maxdepth 5 -name passw
display all empty files(files with sisze 0 bytes) in home folder
find ~ -empty
display all the files in the home folder which begin with "arrow" and end with "xbm"
find ~ -name 'arrow*.xbm'
Remove all core dump files from user's home directory
find ~/ -name 'core*' -exec rm {} \;