nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Copy file header.shtml to directories dir1, dir2, dir3, and dir4
find dir1 dir2 dir3 dir4 -type d -exec cp header.shtml {} \;
Recursively change ownership of "~/.npm" to the current user
sudo chown -R $(whoami) ~/.npm
Search *.x files from the current directory tree for string "fred"
find . -name ‘*.x’ -print0 | xargs -0 grep fred
Find all C source code files from the current directory tree that contain "keyword" in their pathnames, ignoring the case
find . -type f \ |grep -i “keyword”
find all files in the home folder which have been modified between 72 and 96 hours before
find ~ -mtime 2 -mtime -4 -daystart
Set the 'xtrace' shell option
set -o xtrace
Prints calendar for a current month without first day of a week.
cal | sed -e 's/^.\{3\}//' -e 's/^\.\{3\}$/\1/'
extract 'archive.tar.gz' to /destination
gzip -dc archive.tar.gz | tar -xf - -C /destination
Lists all subdirectories in current directory with a trailing slash
ls -d ./*/ ### more reliable BSD ls
Print all filenames under /proc and below
find /proc -exec ls '{}' \;
Find regular files named core under /tmp and delete them
find /tmp -name core -type f -print | xargs /bin/rm -f
Remount "/path/to/chroot/jail/usr/bin" as read only
mount -o remount,ro /path/to/chroot/jail/usr/bin
Send one ping request to local machine.
ping -c 1 127.0.0.1 #ping your adress once
Write the output of command "mongo" to the screen and to file "somefile"
mongo | tee somefile
Print the $N'th line from file by replacing commas with newlines
head -$N file | tail -1 | tr ',' '\n'
change the permission of all the regular/normal files in the current folder from 777 to 755
find . -type f -perm 777 -exec chmod 755 {} \;
Move server.log to 'logs' directory with new name as the current date formatted as "%Y%m%d%H%M" and with '.log' extension
mv server.log logs/$.log
Remove empty folder, and skip error message if one is not empty.
rmdir --ignore-fail-on-non-empty newBaseDir/Data/NewDataCopy
Gets IP address of 'eth0' network interface.
ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'
Remove all empty regular files under the current directory and below
find ./ -type f -empty -print0 | xargs -0 rm
Recursively finds all "*.pas" and "*.dfm" files and prints strings with "searchtext" ignoring text distinctions, suppressing error messages, highlighting found patterns and preceding each found string with file name and string number.
find . -type f \ -print0 | xargs --null grep --with-filename --line-number --no-messages --color --ignore-case "searchtext"
Pass a wildcard to scp by escaping it: copy all files with names starting with "files" in directory "/location" on host "server" to current directory on local machine, displaying debug info and preserving timestamps and permissions on copied files.
scp -vp me@server:/location/files\*
Output "stuff", removing "/foo/bar/" from the specified path.
basename /foo/bar/stuff
find all the normal/regular files in the current folder which have been modified in the last day and display a long listing of them
find . -type f -mtime -1 -daystart -exec ls -l {} \;
Read the history file $HISTFILE and append the contents to the history list
history -r "$HISTFILE" #Alternative: exec bash
Create tar archive "dirall.tar" and copy all files from directory tree /tmp/a1 to it
find /tmp/a1 -exec tar -rvf dirall.tar {} \;
Search for case-insensitive "string" in "log.tar.gz"
zcat log.tar.gz | grep -a -i "string"
find all instances of a specific file in the current directory and discard all the errors.
find . -name "openssl" 2>/dev/null
List files larger than 10MB in the /var directory recursively
find /var/ -size +10M -ls
Save the short DNS lookup output of $WORKSTATION to 'WORKSTATION_IP' variable
WORKSTATION_IP=`dig +short $WORKSTATION`
Creates temporary file and saves path to it in 'content_dir2' variable.
content_dir2=$
Prints process tree of the current command process.
pstree -p $$
List all files under current directory with their sizes and paths
find . -type f -printf '%s %p\n'
Find all files/directories under current directory and print them
find . -print0 | xargs -I{} -0 echo {}
Find all directories with permissions 777 under and below /var/www/html, and change their permissions to 755
find /var/www/html -type d -perm 777 -print -exec chmod 755 {} \;
Print how many files are inside each directory under the current one
find */ | cut -d/ -f1 | uniq -c
Find all *.$input_file_type files/directories under $source_dir with the null character as the delimiter
find "$source_dir" -name "*.$input_file_type" -print0
Extract two semicolon-separated fields from specified strings, output them separated by a space.
echo "[email protected];[email protected]" | awk -F';' '{print $1,$2}'
Forward port 3307 on localhost to port 3306 on 1.2.3.4 via 'user@gateway' on port 24222
ssh -f user@gateway -p 24222 -L 3307:1.2.3.4:3306 -N
Sets the shell prompt to "[USER@HOST]" where USER is the current user and HOST is the short host name
set prompt=\[`id -nu`@`hostname -s`\]\#\
Prints a random number between 2000 and 65000
seq 2000 65000 | sort -R | head -n 1
Search for the case insensitive regex expanded by $2 in all files named $1 under current directory
find . -name $1 -type f -exec grep -i $2 '{}' \;
Run svn checkout in every directory named 'needed_dir' under repository_dir/$f
find repository_dir/$f -type d -name needed_dir | xargs -r svn checkout
Archive "src" to "dst" updating files existing in "dst"
rsync -a -v src dst
Find files/directories writable by group and others under the /path directory
find /path -perm -g+w,o+w
find all the files in the filesystem which do not belong to any group
find / -nogroup -print
List the directory paths of all file.ext files under present working directory
find `pwd` -name "file.ext" -exec dirname {} \;
Find largest file in linux with find command
find . -type f -printf "%s\t%p\n" | sort -n | tail -1
Identify CMS version/releases accross all your PHPBB installations
find /var/www/vhosts/*/httpdocs/ -type f -wholename *includes/constants.php -exec grep -H "PHPBB_VERSION" {} \;
Print a list of regular files from directory tree sort_test/ sorted with LC_COLLATE=C
find sort_test/ -type f | env -i LC_COLLATE=C sort
display all files in current folder in sorted order of depth
find folder1/ -type f -printf "%d\t%p\n" | sort -n | sed -e "s|[0-9]*\t||"
Prints top-ten biggest top-level folders within a 'var' folder.
sudo du -hDaxd1 /var | sort -h | tail -n10
Find command will display top 10 Big files from current directory .
find . -type f -exec ls -s {} \; |sort -n -r |head
Find .jpg files owned by user daniel in the current directory and its sub-directories.
find . -user daniel -type f -name *.jpg
change owner of the file /home/bob to user root
sudo chown root /home/bob
Find all directories under ~/code excluding hidden directories and their subdirectories and replace all newlines with : in the output then remove the last :
find ~/code -type d | sed '/\/\\./d' | tr '\n' ':' | sed 's/:$//'
Search all files in the current directory tree that are named "whatever" for "whatever"
find . -name whatever -print | xargs grep whatever
Print the character representations of 65 to 90
seq 65 90 | awk '{printf("%c",$1)}'
search for the file "job.history" in the folder /data/Spoolln and search for multiple patterns in the file and display the count of matched lines along with the pattern
find /data/SpoolIn -name job.history | xargs grep -o -m 1 -h 'FAIL\|ABOR' | sort | uniq -c
Find the first file/directory under current directory and quit
find . ... -exec sh -c 'printf "%s\n" "$1"; kill "$PPID"' sh {} \;
Force create a symbolc link named "new_dir" to "/other/dir" without dereferencing "new_dir"
ln -sfn /other/dir new_dir
search for all the ".c" files in the folder "/home/david" which have been modified in the last 10 minutes
find /home/david -mmin -10 -name '*.c'
find all the files in the current folder which have the name net or comm in them
find . -regex '.*\.*'
find for a filename with multiple patterns in the current folder
find . -name "photo*.jpg"
Find files/directories with exactly read,write and execute permission for all under /path
find /path -perm ugo+rwx
Count used space on device "/dev/sda" in megabytes
df -h -B 1M | grep dev/sda | tr -s ' '| cut -d' ' -f3 |python -c "import sys; print sum([int for num in sys.stdin.readlines])"
Remove all *.log files from the current directory tree
find ./ -name '*.log' | xargs rm
Search everywhere for directories named `root'
find / -type d -name root
find all text files in current folder and delete all the files that have the word foo in their name
find . -name ".txt" | grep "foo" | xargs rm
search for the regular/normal files iceweasel or thunderbird in the entire file system and exclude search in the paths /export and directories having the word Recommeded in their name
find / \ -prune -o \ \ -print 2>/dev/null
display all the files in the current folder which hare in the sub directory trees of the folders which begin with the word "kt" followed by a digit
find . -path './kt[0-9] '
replaces the last occurrence of 'a' with 'c' in file
tac file | sed '/a/ {s//c/; :loop; n; b loop}' | tac
List all regular files from the current directory tree that were modified less than 60 minutes ago
find . -type f -mmin -60 | xargs -r ls -l
Concatenate all .txt files residing in the current directory tree
find . -name '*.txt' -not -name "all.txt" | xargs cat > all.txt
Search for 'Attached: Yes' in all regular files under '/proc/scsi' directory tree matching the path '/proc/scsi/usb-storage' and show only the matched filenames
find /proc/scsi/ -path '/proc/scsi/usb-storage*' -type f | xargs grep -l 'Attached: Yes'
Find all the *.pl files beneath the current directory.
find . -name "*.pl"
SSH in server 'server' as user 'user' with X11 forwarding disabled
ssh -x user@server
find all the files in the file system which have been modified in the last 60 minutes
find / -mmin -60
move all the files in the current folder to temp folder and search atleast in one subfolder
find . -mindepth 1 -print0|xargs -0 -I, mv , /tmp
Remove all files in and below the current directory whose names begin with "not"
find . -name not\* | tr \\n \\0 | xargs -0 rm
Recursively finds all '*.pdf' files in a current folder and removes them without prompting.
find . -name '*.pdf' -exec rm -f {} \;
Make directories "a/b/c" as needed without causing an error if it exists
mkdir -p a/b/c
List all *.java files/directories under /home/bluher with their full paths
find /home/bluher -name \*.java
display all the directories in the folder master-
find master -type d | sort
Show all lines as they are executed and stop at the first command returning nonzero
set -ex
List all *.png files/directories under /home/kibab directory
find /home/kibab -name '*.png' -exec echo '{}' ';'
Search for "#define" in all files in the current directory, excluding backup files *~, *.orig, *.bak
find . -maxdepth 1 ! -regex '.*~$' ! -regex '.*\.orig$' \ ! -regex '.*\.bak$' -exec grep --color "#define" {} +
Read a single character from standard input and do not allow backslash to escape characters
read -rn1
display a long listing of the files in current folder which have been modified in the last 60 minutes
find . -mmin -60 -type f -exec ls -l {} +
display a list of all the files in the file system which do not belong to any user and search only in jfs and jfs2 file systems
find / -nouser \( -fstype jfs -o -fstype jfs2 \) -ls
Find the passwd file under root and one level down.
find -maxdepth 2 -name passwd
Print every two lines in "num.txt" on a single line separated by a space
paste -d' ' < <
Save the number of modified files in a git repository in variable "MYVAR"
MYVAR=`git ls-files -m|wc -l|tr -d ' '`
find all regular files then display the number of occurrences of banana without lines not proper end
find . -type f -print0| xargs -0 grep -c banana| grep -v ":0$"
create directory /etc/cron.minute
mkdir /etc/cron.minute
download contents from "http://example.com/" using a socks5 proxy "125.119.175.48:8909"
curl --socks5 125.119.175.48:8909 http://example.com/
Removes all files from current folder but 5 newest ones.
ls -C1 -t| awk 'NR>5'|xargs rm
find files in the users home directory and for each one, ask the user to confirm to delete the file.
find $HOME/. -name *.txt -ok rm {} \;
Find all directories on the system whose size is greater than 50k
find / -type d -size +50k
delete all the files ending with "~" in current folder
find . -name "*~" -print | xargs rm