nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all .* files excluding list_files under current directory
find . -iname ".*" \! -iname 'list_files'
Write output and error of "bash myscript.sh" to standard output and to "output.log"
bash myscript.sh 2>&1 | tee output.log
find the oldest normal file in the current directory and display its contents
find -type f -printf "%T+ %p\0" | sort -z | grep -zom 1 ".*" | cat
Find all *.tar.gz files/directories under /directory/whatever which were modified more than $DAYS ago and show a message if no files were found
find /directory/whatever -name '*.tar.gz' -mtime +$DAYS | grep 'tar.gz' || echo "You don't have files older than $DAYS days"
Print a colon-separated list of all directories from the ~/code directory tree, except hidden ones
find ~/code -type d -name '[^\.]*' | tr '\n' ':' | sed 's/:$//'
Print a sorted list of unique directory paths in entire file system that match the pattern '<name_pattern>' in their names
find / -name '<name_pattern>' -type d | sort | uniq
Find all directories under /home/username/public_html/themes and set their permission to 750
find /home/username/public_html/themes -type d -exec chmod 750 {} +
Find all files/directories under 'A' directory tree excluding directory 'A/a' and all of it's contents
find A \! -path "A/a/*" -a \! -path "A/a"
Search the home directory tree for .tar.gz files newer than file "filename"
find ~/ -name *.tar.gz -newer filename
Rename all *.html files under and below the current directory to *.var
find -name '*.html' -print0 | xargs -0 rename 's/\.html$/.var/'
search for the file "process.txt" in the entire file system
find / -name "process.txt"
Search directory trees /tmp and /var/tmp for "testfile.txt"
find /tmp /var/tmp -iname "testfile.txt"
display all the files in the current folder excluding the files with the name mmm
find . -name mmm -prune -o -print
display all the ip addresses in all the files that are present in /etc folder
find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' | grep '^[^.][^.]*\.[^.][^.]*\.[^.][^.]*\.[^.][^.]*$'
Execute "ps -C java -o pcpu,state,cputime,etimes" every second
watch -n 1 ps -C java -o pcpu,state,cputime,etimes
Recursively list all files on smbfs mounts
mount -v | grep smbfs | awk '{print $3}' | xargs ls -lsR
Make directories and parents for each line in "infile" excluding the file name
while read line; do mkdir -p "${line%/*}"; done < infile
find all normal/regular files in the folder "//path/to/source/Directory" and calculate the md5sum of them and save the output to file Output.txt
find //path/to/source/Directory -type f -exec md5sum {} + | awk '{print $0}' > Output.txt
Make directories and parents for each file path in "somefile.txt" excluding the file name
xargs -n 1 dirname <somefile.txt | xargs mkdir -p
Find all files in the current directory tree that are newer than some_file
find . -newer some_file
find files with pattern` '*.h' and print comparison between file and /tmp/master directory
find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'
Find all files/directories under current directory excluding the paths that match the POSIX extended regex ".*def/incoming.*|.*456/incoming.*"
find . -regex-type posix-extended -regex ".*def/incoming.*|.*456/incoming.*" -prune -o -print
recall the second argument from a previous command by pressing alt-shift-y
bind '"\eY": "\e2\e."'
find all the text files in the current folder expect those which are in the path "sk"
find . -path "./sk" -prune -o -name "*.txt" -print
Print file system disk space usage with a grand total
df --total
Display inputfile all on one line (replace newlines by spaces)
awk '{printf "%s ", $0} END {printf "\n"}' inputfile
display all files in the current folder after pruning those in the current folder
find . -prune -print
search for a word in all the files in the entire filesystem and display the matched fline along with the file name
find / -type f -exec grep -Hi 'the brown dog' {} +
Find all directories under /home/me/"$d"
find /home/me/"$d" -type d
Change all files in the current directory tree to owner "xx"
find . \
Find all regular files under current directory
find . -type f
Search file /etc/logs/Server.log for lines containing "Error"
find /etc/logs/Server.log -exec grep Error {} \; -print
Lists all files in a current folder, separating names with space.
ls -1 | awk 'ORS=" "'
Find all regular files in the "aaa" directory
find aaa/ -maxdepth 1 -type f
Removes all files like 'A*.pdf' from current folder without prompting.
rm -f A*.pdf
List the current directory recursively ignoring the "dir1" subdirectory's content
find . -print -name dir -prune
Find all PHP files under current directory that contain only one line
find . -type f -name '*.php' -exec grep -Hcm2 $ {} + | sed -n '/:1$/{s///;p}'
Print A record for domain 'domain.' from 'some.other.ip.address' nameserver
dig @some.other.ip.address domain. a
Print 'infile' content with line numbers
cat -n infile
Locate python interpreter and show its human-readable file type description, resolving any symlinks.
file -L $(python -c 'import sys; print')
Count the number of files named 'job.history' under '/data/SpoolIn' directory tree that match 'FAIL' in their contents
find /data/SpoolIn -name job.history -exec grep -l FAIL {} \; | wc -l
Search the /dir directory tree for files whose names match regular expression '.*2015.*\(album.*\|picture.*\)'
find /dir -regex '.*2015.*\(album.*\|picture.*\)'
Find all files in current directory and execute command1 and command2 for each file
find . -type f \
delete all the files ending with "~" in current folder
find -name '*~' -print0 | xargs -0 rm
Print the list of the subdirectories of /path/to/dir
find /path/to/dir/ -mindepth 1 -maxdepth 1 -type d
Find files/directories that are owned by the user 'syslog' in entire filesystem
find / -user syslog
find all the wav files in the current folder and do not search in the sub directories
find . -name '*.wav' -maxdepth 1
Find all *.ogg files on the system ignoring the case
find / -iname '*.ogg'
Remove all files and directories called "test" from the current directory tree
find . -name test -delete
set alias "h" for command "history"
alias h='history'
Assign a name when starting a screen session
screen -S 'name' 'application'
search for text files in the current folder which do not have write access to others
find . -type f \( -iname "*.txt" -not -perm -o=w \)
display all the text files in current folder
find . -name "*.txt"
find all the files in the file system which have read permission to the user and display the ten files
find / -perm /u=r | head
Print a list of all the files in entire file system whose inode has been modified no later than one minute ago
find / -newerct '1 minute ago' -print
Find all *.txt files under the current directory whose names are not "File.txt"
find . -maxdepth 1 -type f -regex '.*\.txt' -not -name File.txt
Search directories /opt, /usr, /var for regular file foo
find /opt /usr /var -name foo -type f
compress all the non-compressed files in the current directory.
find . \! -name "*.Z" -exec compress -f {} \;
find all the file that have been modified exactly 3 days ago
find ./ -daystart -mtime -3
Search all non-hidden files in the current directory and all non-hidden sub-directories for the file hi.dat.
find *-name hi.dat
display all the users in the current folder that belong to the group "sunk"
find . -type f -group sunk
Find all regular files with name pattern $filename under $fileloc directory tree
find "$fileloc" -type f -prune -name "$filename" -print
Keep the last 4 ASCII characters (bytes) of a string.
echo "0a.00.1 usb controller some text device 4dc9" | rev | cut -b1-4 | rev
Mount "vfat" filesystem "/dev/sda7" to "/mnt/my_partition" with read and write permission, umask of files and directories set to "0000", and save in fstab and allow ordinary users to mount
sudo mount -t vfat -o rw,auto,user,fmask=0000,dmask=0000 /dev/sda7 /mnt/my_partition
Create a rsa key of 2048 bits with comment "michael" and store it in file "key".
ssh-keygen -b 2048 -t rsa -f key -C michael
Dry run making directories in "/TARGET_FOLDER_ROOT/" for each ".mov" file in the current directory tree
find . -type f -iname \*.mov -printf '%h\n' | sort | uniq | xargs -n 1 -d '\n' -I '{}' echo mkdir -vp "/TARGET_FOLDER_ROOT/{}"
Print a welcome message with the current user's user name
echo "Welcome $!"
Print a count of all unique lines in "ports.txt" sorted from most frequent to least frequent
sort ports.txt | uniq -c | sort -r
display all the details of empty files in current folder
find . -size 0 -printf '%M %n %u %g %s %Tb\n \b%Td %Tk:%TM %p\n'
Get the total size of all files under dir1 directory
find dir1 ! -type d -printf "%s\n" | awk '{sum += $1} END{print sum}'
Make directories as needed in "dest" for every directory found under "src/"
find src/ -type d -exec mkdir -p dest/{} \;
Find all HTML files starting with letter 'a' in the current directory and below
find . -name a\*.html
Saves value '1' in the $PIPESTATUS variable and returns 0.
false | tee /dev/null
List all *.jar files/directories under /usr, /home and /tmp directory
find /usr /home /tmp -name "*.jar"
Prints path to the target of symbolic link 'relative/path/to/file'
dirname `readlink -e relative/path/to/file`
Creates temporary file in a current folder with name formatted like 'templateXXXXXX', and saves path to it in 'tempfile' variable.
tempfile=$(mktemp $(pwd)/templateXXXXXX)
set alias "my_command" for command "$oldalias --fail-if-command-contains=$bad_string"
alias my_command="$oldalias --fail-if-command-contains=$bad_string"
Find all directories and for each of them, print an mv command to move it to /new/location
find . -type d -execdir echo /bin/mv {} /new/location \;
Find all the SGID files in the current directory tree
find . -perm /g+s
Print lines 10000 to 10010 from input "seq 1 100000"
seq 1 100000 | tail -n +10000 | head -n 10
Find all files excluding files ending with 'gz', 'tmp' and 'xftp' in their names in the current directory tree and compress them with gzip not preserving timestamp and original name
find . -type f ! \ -exec gzip -n '{}' \;
Find directories modified in last 7 days
find . -mtime -7 -type d
display all the text files in the current folder which have been modified in the last half minute
find . -mmin 0.5
Search the current directory tree for regular files that were modified $FTIME days ago
find . -type f -mtime $FTIME
Print out ln commands for each file in /home/folder1/*.txt that can be run to create symlinks appending '_CUSTOM_TEXT.txt' in their names
find /home/folder1/*.txt -type f | awk -F '.txt' '{printf "ln -s %s %s_CUSTOM_TEXT.txt\n", $0, $1}'
Changes group ownership of 'public' and 'private' to 'god'.
chgrp god public private
Recursively change owner to "tomcat6" of "webapps", "temp", "logs", "work", and "conf"
chown -R tomcat6 webapps temp logs work conf
search for a cpp directory in current folder and display all its files
find . -type d -name "cpp" -exec find {} -type f \;
Generates default-formatted file name of temporary file in a /dev/mapper folder, and saves path to it in a variable 'MAPPER'.
MAPPER=$(mktemp -up /dev/mapper)
Search the .c files residing in the Lib/ directory tree for lines beginning with "PyErr"
find Lib/ -name '*.c' -print0 | xargs -0 grep ^PyErr
Remove all files and directories under '/home/foo' directory tree that match with one of the name patterns '.DS_Store', '._.DS_Store' , '._*', '.TemporaryItems' or '.apdisk'
find /home/foo \ -exec rm -rf {} \;
Copy all files in "/var/spool/mail" to "/home/username/mail" preserving the directory hierarchy and modification times
find /var/spool/mail -type f | cpio -pvdmB /home/username/mail
Find all files throughout the entire file hierarchy with the optional constraints of опция_поиска, значение and/or опция_действия.
find / [опция_поиска] [значение] [опция_действия]
find all the swap files (files ending with ~) in the current folder and delete them
find . -name "*~" -delete
use regex with find command
find . * | grep -P "[a-f0-9\-]{36}\.jpg"
List files under current directory which were modified, accessed or whose status were changed $FTIME ago and sort them and remove duplicate entries
| sort | uniq
Print full path of command "python"
which python
Creates temporary folder within TMPDIR, with name like current shell name and 10-letter suffix.
mktemp -dt "$(basename $0).XXXXXXXXXX"
Disable jobs running in their own process group in the shell
set +m
Find all files in /dir1 and print only the filenames (not paths)
find /dir1 -type f -printf "%f\n"