nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Mathematically sum all lines in "filename"
cat filename | python -c"from fileinput import input; print sum(map(int, input))"
update the permission of all the files in the folder /u/netinst to 500
find /u/netinst -print | xargs chmod 500
display all the files in current folder which have write permission to all the users
find . -perm /222
find md5sum of 'string to be hashed'
echo 'string to be hashed' | md5
Enables shell option 'lithist'.
shopt -s lithist
Find all "G*.html" files modified more than 7 days ago in the current directory tree
find . -mtime +7 -name "G*.html"
Find all *.srt files under directory named 'working' and show the first one found
find working -type f -name "*.srt" | head -1
Find only number of hard link & name of files from long list
find -type f -iname "*.txt" -exec ls -lrt {} \;|awk -F' ' '{print $1 $2 $9}'
Find all files with '.conf' extension under '/etc' directory going into at most 2 level deep and show the last 10 of them
find /etc -maxdepth 2 -name "*.conf" | tail
Count the number of lines in "myfile.txt"
cat myfile.txt | wc -l
display all the files in the current folder excluding those that are present in the sub directory aa and display those files that start with the word "file"
find . \ -o \
display all files in current folder excluding current folder (.)
find . \! -name '.'
Find all httpd.conf files in entire file system
find / -name httpd.conf
Execute "ls -l" every 2 seconds
watch 'ls -l'
Unzip all ".gz" files in the current directory tree to their respective directories
find . -name "*.gz" -execdir gunzip '{}' \;
Get the disk space used by all *.txt files/directories under current directory
find . -name "*.txt" -print0 |xargs -0 du -ch | tail -n1
find files which full path name is /tmp/foo/bar under foo directory and print
find /tmp/foo -path /tmp/foo/bar -print
find all the files that have been modified since the last time we checked
find /etc -newer /var/log/backup.timestamp -print
Find all files under and below /dir that were modified less than 60 minutes ago
find /dir -mmin -60
Save the list of files in the current directory hierarchy separting file names with zeroes
find . -print0 > mypipe
Find all filenames ending with .c in the current directory tree, case insensitive
find -iname "*.c"
Request NS record for com. domain, receiving only authoritative answers
dig NS +aaonly com.
Copy file or directory 'gtest' from directory 'include' in current directory to /usr/include, preserving ownerships and permissions.
sudo cp -a include/gtest /usr/include
Print A record for domain 'domain.' from 'some.other.ip.address' nameserver
dig @some.other.ip.address domain. a
display the name of all directories in the current folder and do not search in sub directories
find . -type d -maxdepth 1 -exec basename {} \;
search normal files called ' banckup ' from /usr directory downward and print them.
find /usr -type f -name backup -print
create directory tata
mkdir tata
Join comma-separated information in 4 files - files must be sorted.
join -t, test.1 test.2 | join -t, - test.3 | join -t, - test.4
recursively change owner of the directory /Users/xxx/Library/Developer/Xcode/Templates and all files to user xxx
sudo chown -R xxx /Users/xxx/Library/Developer/Xcode/Templates
Print a single line of numbers from "001" to "010"
yes | head -n 10 | awk '{printf( "%03d ", NR )}'
Prints top-ten list of most used utilities from history.
history | awk '{ print $2 }' | sort | uniq -c |sort -rn | head
Unzip all files that match "*.gz" in the current directory and subdirectories to stdout and search for "test"
find . -name "*.gz" -exec zcat "{}" + |grep "test"
Find a file "foo.bar" without showing "Permission Denied" messages
find / -name foo.bar -print 2>/dev/null
display all the regular files in the current folder excluding those that are present in the path "git"
find . -path "*.git*" -prune -o -type f -print
Gets a current job back to the foreground.
fg
Find all read only files in /home directory
find /home -type f -perm /u=r
Find all regular files named 'Chapter1' under current directory tree
find . -name Chapter1 -type f -print
search all the files in the current folder using regex excluding those that are present in the folder test
find . -name test -prune -o -regex ".*/my.*p.$"
Find files/directories named blah (case insensitive) under current directory
find ./ -iname blah
Remove all empty sub-directories under current directory
find . -depth -type d -empty -exec rmdir {} \;
List regular files in current directory with read, write and execute permission for all users and also show the permissions
find . -type f -perm a=rwx -exec ls -l {} \;
list all running jobs
jobs
Split the contents of "file1 file2 ... file40000" into 1445 files in a round robin fashion with prefix "outputprefix" and numeric suffixes
cat file1 file2 ... file40000 | split -n r/1445 -d - outputprefix
Exit the shell on the first error encountered
set -o errexit
Delete history entry at offset, defined in first argument of executed script
history -d "$1"
list all files under .performance_test directory except .performance_test/prune_me directory
find ".performance_test" -path ".performance_test/prune_me" -prune -o -exec bash -c 'echo "$0"' {} \;
Search the current directory tree for files whose names start with "f"
find . -name f* -print
Print common files of directory "1" and "2"
comm -12 <(ls 1) <(ls 2)
Removes first and last parts of path $path and saves the result in 'finalName' variable.
finalName=$(basename -- "$")
find all the files with the name september ( case insensitive )
find -iname september
Change owner to "root" and group to "dockerroot" of "/var/run/docker.sock"
sudo chown root:dockerroot /var/run/docker.sock
Print all user names and terminals of users who are logged in
who | cut -d " " -f1,2
Find all files/directories named 'Waldo' under 'Books' directory tree that is located in user's home directory
find ~/Books -name Waldo
find all the directories in the home folder do not search in sub directories
find /home -maxdepth 1 -type d
Change permissions of all files ending ".php" under the current directory to 755 and print a count of modified files
find . -name "*.php" -exec chmod 755 {} + -printf '.' | wc -c
Print the current user name and inode number of "/home"
echo `whoami` `stat -c %i "/home"`
Find all regular files in the current directory tree whose names are "YourProgramName", change to the directories they are in, and execute them with parameter "YourParameterFile"
find . -type f -name YourProgramName -execdir ./YourProgramName YourParameterFile \;
Save absolute path of "$path" that may not exist to variable "abspath"
abspath=$
change the group of all directories in the current folder
find . -type d -exec chgrp usergroup {} \;
Search the "test1" directory recursively for regular files named "textfile.txt"
find test1 -type f -name 'textfile.txt' -print
Allocate a pseudo-terminal and execute "screen -r" followed by "ls" on host "example.com"
ssh -t example.com "screen -r; ls"
Print multiline text "ONBOOT=\"YES\"\nIPADDR=10.42.84.168\nPREFIX=24" to the terminal, replacing '\n' with newline symbol, and append that text to file /etc/sysconfig/network-scripts/ifcfg-eth4 as root user.
echo -e "ONBOOT=\"YES\"\nIPADDR=10.42.84.168\nPREFIX=24" | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-eth4
Print the names of all regular files in the current directory tree
find . -type f -exec echo {} \;
Prints process tree for the current process with ASCII line drawing characters.
pstree -A -s $$
Calculate md5 sum of empty string
echo -n "" | md5sum
find all files which name contain 'foo' and path is not dir1 or dir2
find ! -path "dir1" ! -path "dir2" -name "*foo*"
Set variable BZIP2_CMD to the full path of command "bzip2"
BZIP2_CMD=`which bzip2`
Find writable regular files in the current directory
find -type f -maxdepth 1 -writable
Move all files and directories in the current directory to "$TARGET" excluding files matching "$EXCLUDE"
ls -1 | grep -v ^$EXCLUDE | xargs -I{} mv {} $TARGET
search for all the files in the current folder which have the word "-GHBAG-" and display the move command for replacing the word "GHBAG" in the file names to "stream-agg"
find . -name '*-GHBAG-*' -exec bash -c 'echo mv $0 ${0/GHBAG/stream-agg}' {} \;
show all the files in current directory
find .
Force create a symbolc link named "/usr/local/bin/fpt" to "/usr/local/bin/findpdftext"
sudo ln -s -f "/usr/local/bin/findpdftext" "/usr/local/bin/fpt"
Sets shell option 'dotglob'.
shopt -s dotglob
Find all Read Only files in entire file system and show a few lines of output from the beginning
find / -perm /u=r | head
Find all files/directories named 'query' under current directory
find -iname "query"
Print the full path of a file under the current working directory with inode number specified on standard input
xargs -n 1 -I '{}' find "$" -type f -inum '{}' -print
Print appended data in "/var/log/some.log" that match "foo" and "bar"
tail -f /var/log/some.log | grep --line-buffered foo | grep bar
Query SRV records for domain '_kerberos._udp.foo.com'
dig -t SRV _kerberos._udp.foo.com
Prints directory where the executing script is located.
`dirname $0`
Interactively display all lines containing 'word' in all files whose name ends with .properties in the current directory, waiting for user input after each page.
grep -R 'word' *.properties | more
search for files in the current folder which start with "myfile" ( case insensitive search )
find . -iname 'MyFile*'
find md5sums of files named "file*.txt"
md5sum file*.txt
Search everywhere for a file called `httpd.conf' that is newer than /etc/apache-perl/httpd.conf
find / -name httpd.conf -newer /etc/apache-perl/httpd.conf
display all normal/regular files in the folder "pathfolder"
find pathfolder -type f
Find all subdirectories of the current directory except hidden ones
find -maxdepth 1 -type d ! -name ".*"
Print name of user with current EUID.
ps -o user= -p $$ | awk '{print $1}'
Search for a pattern "can't" in all the files with the name "file-containing-can't" in the current directory tree
find . -name "file-containing-can't" -exec grep "can't" '{}' \; -print
find all the files in the current folder that are modified after the modification date of a file
find . -newer document -print
display all files in the directory "dir" which have been changed in the last 60 minutes
find /dir -cmin -60
Print the ping statistics of 4 requests to "www.google.com"
ping -c4 www.google.com | awk '/---/,0'
Find all $1 files/directories under current directory and enter into the parent directory of the first one found
cd $(find . -name $1 | xargs dirname)
find md5sum of content from "www.google.com"
curl -s www.google.com | md5
sort each file in the bills directory, leaving the output in that file name with .sorted appended
find bills -type f -execdir sort -o '{}.sorted' '{}' ';'
Clone the permissions of "$srcdir" to "$dstdir"
chown $ "$dstdir"
Add "prefix_" to every non-blank line in "a.txt"
nl -s "prefix_" a.txt | cut -c7-
Find files under /usr that are newer than the first file `FirstFile'
find /usr -newer /usr/FirstFile -print
Print the file names along with their sizes under current directory tree
find . -type f -printf "%f %s\n"
Find and show all files in the current directory tree that are smaller than 500 kB
find . -size -500k
find files in home directory that names are game
find ~ -name game
set alias "cd-" for command 'cd ${${$}[3]}'
alias cd-='cd ${${$}[3]}'