nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Save number of strings with $expression pattern in 'foo.txt' to 'big_lines' variable.
big_lines=`cat foo.txt | grep -c "$expression"`
Save list of groups which user $line belongs to and not matching pattern "_unknown|sciences|everyone|netaccounts" in 'results' variable
results=$
Find all empty directories under a certain path
find /tmp -type d -empty
Search PATH for utilities called "rename", display the type of file for each match found.
which -a rename | xargs readlink -f | xargs file
Find all files/directories under current directory tree whose names start with 'some_text_2014.08.19'
find . -name 'some_text_2014.08.19*'
Recursively finds strings with 'word-1' or 'word-2' in any file under 'directory-path', following symlinks, and prints found strings.
egrep -R "word-1|word-2” directory-path
delete all the trace files from the folder $DBA/$ORACLE_SID/bdump/ which have not been accessed in the last 7*24 hours
find $DBA/$ORACLE_SID/bdump/*.trc -mtime +7 -exec rm {} \;
Print environment variable "IFS" and its value
set | grep ^IFS=
Set permissions for all direcotries under /var/www to 755
find /var/www -type d -print0 | xargs -0 chmod 755
Find executable files
find . -perm -100 -print
find all files in the file system whose size is exactly 2KB
find / -size 2048c
Print the list of all regular files on the system using "echo"
find / -type f -exec echo {} \;
display all the users in the current folder that belong to the group "sunk"
find . -type f -group sunk
Display a binary file as a sequence of hex codes
od -t x1 file|cut -c8-
Disables shell option 'nocasematch'.
shopt -u nocasematch
Find all *.c files under and below the current directory that contain "hogehoge"
find . -name \*.c | xargs grep hogehoge
Find files/directories named 'sar' under directory trees whose path starts with '/u' or '/b' or '/s' or '/o'
find `ls -d /[ubso]*` -name sar
find Texinfo source files in /usr/local/doc
find foo -path foo/bar -print
Create a variable CDATE in the current shell that contains the date in '%Y-%m-%d %H:%M:%S' format , and a variable EPOCH that contains the seconds since epoch
source <
Find all files/directories named 'top' in the entire filesystem
find / -name top
Create symbolic links in the current directory for all files excluding "CONFIGFILE" located under "/your/project" directory tree
find /your/project -type f ! -name 'CONFIGFILE' -exec ln -s \{\} ./ \;
Search the entire file hierarchy for files ending in '.old' and delete them.
find / -name "*.old" -exec /bin/rm {} \
Count the number of files in the /usr/ports directory tree whose names begin with 'pkg-plist' and which contain 'dirrmtry'
find /usr/ports/ -name pkg-plist\* -exec grep dirrmtry '{}' '+' | wc -l
Interactively page through the color-coded output of 'ls'.
ls --color | less -r
Print the full path prefix for all files in the current directory tree as a list
tree -fi
find all regular files which have been modified in the last 48 hours in home folder
find ~ -type f -mtime -2
move all the html files from current folder to another folder and if a symbolic link is found copy the original referenced file and not the link
find . -follow -iname '*.htm' -print0 | xargs -i -0 mv '{}' ~/webhome
Archive "/path/to/files" to "user@targethost:/path"
rsync -av /path/to/files user@targethost:/path
Find all *.jpg files on the system
find / -name *.jpg 2>/dev/null
display all the files in the entire file system
find / -name "*" — print
Print the list of files in the current directory tree skipping SVN files
find . -name .svn -a -type d -prune -o -print
Find all files/directories in entire file system that are owned by "shadow" group
find / -group shadow
find all the files in the current directory and search for the word "pw0" in them.
find . -exec grep -i "pw0" {} \;
Delete files in /var/tmp/stuff and below that have not been modified in over 90 days
find /var/tmp/stuff -mtime +90 -delete
Remove everything in the current directory except files matching regular expression "exclude these"
find . -maxdepth 1 | grep -v "exclude these" | xargs rm -r
Print the user name of the user running sudo
who -m | awk '{print $1}'
Set permissions to 600 for regular files under var/
find var/ -type f -exec chmod 600 {} \;
Search the directory tree /tmp for regular files using zero delimiter for output
find /tmp -type f -print0
Prints process tree of a process having id $mypid, with command options and process id number.
pstree -aAp $
Find all *.m4a files under /home/family/Music directory and convert them to ogg
find /home/family/Music -name '*.m4a' -exec ffmpeg -i "{}" -acodec libvorbis -aq 6 -vn -ac 2 "{}.ogg" \;
Find every file/directory under the directory /home owned by the user joe
find /home -user joe
Recursively changes group ownership of everything within '/git/our_repos' to 'shared_group'.
chgrp -R shared_group /git/our_repos
Find all files/directories under $1 which have at least execute permission for their owner and set execute permission for group for these files/directories
find $1 -perm -u+x -exec chmod g+x {} \;
Remove everything within parentheses and substitute all non digit characters with a space from "1/2 [3] (27/03/2012 19:32:54) word word word word 4/5" and format the output as a table
echo '1/2 [3] (27/03/2012 19:32:54) word word word word 4/5' | sed -e 's/(.*)//' -e 's/[^0-9]/ /g' | column -t
Returns exit code 1.
a=$(false)
Delete all files/directories named 'sample' (case insensitive) under '/home/user/Series/' directory tree as super user
sudo find /home/user/Series/ -iname sample -print0 | sudo xargs -0 rm -r
set alias "logspace" for command "find /apps/ /opt/ -type f -size +100M -exec ls -lh {} \; | awk '{print $5, $9 }'"
alias logspace="find /apps/ /opt/ -type f -size +100M -exec ls -lh {} \; | awk '{print $5, $9 }'"
Search every directory except the subdirectory excluded_path for a regular file 'myfile'
find / -path excluded_path -prune -o -type f -name myfile -print
change owner and group of all files and directory into current directory to user and group apache
find . -maxdepth 1 -not -name "." -print0 | xargs --null chown -R apache:apache
display all the files only in the path "./sr*sc"
find . -path "./sr*sc"
Recursively change owner and group to "$JBOSS_AS_USER" of "$JBOSS_AS_DIR/"
chown -R $JBOSS_AS_USER:$JBOSS_AS_USER $JBOSS_AS_DIR/
create directory backup
mkdir backup
change group of the file /var/lib/php/session to group lighttpd
chown -R :lighttpd /var/lib/php/session
Print "echo ping -c 2" on each string in file 'ips'
cat ips | xargs -n1 echo ping -c 2
Clear the terminal's search history
history -c
find all files beneath the current directory that begin with the letters 'Foo' and delete them.
find . -type f -name "Foo*" -exec rm {} \;
Get a list of all hidden files from the current directory tree
find . -type f -name '.*'
Recursively change the owner of all files in "~/tmp" to "$USER"
sudo chown -R $USER ~/tmp
Count the number of lines in every regular .rb file in the current directory tree
find . -name "*.rb" -type f -exec wc -l \{\} \;
Find all 777 permission directories and use chmod command to set permissions to 755
find / -type d -perm 777 -print -exec chmod 755 {} \;
Print the time of last boot
who -b
search for all perl files in the folder /nas/projects/mgmt/scripts/perl which have been modified yesterday
find /nas/projects/mgmt/scripts/perl -mtime 1 -daystart -iname "*.pl"
Just find directories and skip file names
find / -type d -name "apt" -ls
Print current shell using process ID
ps -ef | grep $$ | grep -v grep
Strips last section from the path $pathname, and prints basename of the rest part.
echo $(basename $(dirname $pathname))
Copy '/path/to/source' from remote "username@computer" to local "/path/to/dest"
rsync -r username@computer:/path/to/source /path/to/dest
find all the regular/normal files in the current folder which belong to the group "flossblog"
find . -group flossblog -type f
Find all *.tex regular files under current directory
find . -type f -name "*.tex"
Save 'echo whatever you "want your" command to be' in history
history -s 'echo whatever you "want your" command to be'
Output the string 'yes' continously until killed
yes
find all files under the /etc directory and display IP address patterns in them
find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' \ | grep '^[^.][^.]*\.[^.][^.]*\.[^.][^.]*\.[^.][^.]*$'
list the first line in every text file under the users home directory into report.txt
find $HOME/. -name *.txt -exec head -n 1 -v {} \; > report.txt
Count the number of differing lines in "file1" and "file2" with 0 lines of unified context
diff -U 0 file1 file2 | grep -v ^@ | wc -l
Find user daniel's files of type jpeg without `autumn' in the name
find . -user daniel -type f -name *.jpg ! -name autumn*
display all the configuration files in "/etc" folder along with their last access and modified timestamps
find /etc -name "*.conf" -printf "%f accessed %AF %Ar, modified %TF %Tr\n"
create a compressed archive "filename.tar.gz" with verbose output
tar -cvzf filename.tar.gz folder
Find files named "needle" ignoring the case
find . -iname "needle"
Create a copy of the current working directory structure in the usr/project directory,
find . -type d -print|sed 's@^@/usr/project/@'|xargs mkdir -p
Print pathnames of all files in the current directory and below skipping files under SCCS directories
find . -print -name SCCS -prune
Print the current user's mail file in "/var/spool/mail"
cat /var/spool/mail/`whoami`
Find all files under /path and calculate their md5sum
find /path -type f -print0 | xargs -0 md5sum
Search for directories that contain the phrase "foo" but do not end in ".bar"
find . -name '*foo*' ! -name '*.bar' -type d -print
Find all files, folders, symlinks, etc in the current directory recursively
find .
Search /usr/bin for regular files that have been modified within the last 10 days
find /usr/bin -type f -mtime -10
Read a line from standard input into variable "response" ignoring backslash escapes and using the prompt "${1:-Are you sure? [y/N]} "
read -r -p "${1:-Are you sure? [y/N]} " response
Display a long listing of the oldest file under '/hom/backups' directory tree
find /home/backups -printf "%T@ %p\n" | sort -n | head -1 | cut -d" " -f2- | xargs ls -al
Generate UUIDs for the files from the current directory tree
find . -printf "%P\0" | sort -z | while IFS= read -d '' -r f; do echo "$ $f"; done
Print the IP addresses for the current host name
hostname -I | cut -f1 -d' '
display all files in current folder ending with "~" or "#" using regular expression
find -regex "^.*~$\|^.*#$"
Set the shell prompt to "host:pwd>"
PS1=`hostname`':\W> '
find all directories named build under the current directory
find . -type d -name build
delete all the trace files (".trc") from the folder $DBA/$ORACLE_SID/bdump/ which have not been accessed in the last 7*24 hours
find $DBA/$ORACLE_SID/bdump/*.trc -mtime +7 -exec rm {} \;
Search for files whose size is between 100 kilobytes and 500 kilobytes
find . -size +100k -a -size -500k
Recursively find the latest modified file in the current directory
find . -type f -print0|xargs -0 ls -drt|tail -n 1
delete all files in the home directory which ahve the name core in them
find ~/ -name 'core*' -exec rm {} \;
Find all files/directories under /usr/tom which matches the extended regex '*.pl| *.pm' in their names
find /usr/tom | egrep '*.pl| *.pm'
Print the first 5 decompressed lines of compressed file "$line"
zcat "$line" | head -n5
display all files in current directory discard any errors and save the output to a file
find . 2>&1 | grep -v 'permission denied' > files_and_folders
Find all *fink* files/directories in entire file system
find / -name "*fink*" -print
Replace all URLs in "MyHTMLFile.html" with "$pub_url" and create a backup with suffix ".bak"
sed -i.bak "s#https.*\.com#$pub_url#g" MyHTMLFile.html