nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find all files changed on the 29th of September, 2008, starting from the current directory
find . -type f -newerct 2008-09-29 ! -newerct 2008-09-30
display all the files in the file system which belong to the user "wnj" and which are modified after the file "ttt"
find / -newer ttt -user wnj -print
Recursively add ".jpg" to all files without an extension in the directory tree "/path"
find /path -type f -not -name "*.*" -exec mv "{}" "{}".jpg \;
Print only first line of 'file' content, formatted as 29-symbol wide column
cat file | fold -w29 | head -1
Print unique lines of sorted file "a" and "b" and remove leading tabs
comm -3 a b | sed 's/^\t//'
Send 4 ping packets of size 2 to "www.google.com" on a Solaris machine
ping -s www.google.com 2 4
search for all the files excluding directories ending with old or sccs or core or orig in the project folder and append the output to the file exclude
find . -type f -print | \ egrep '/,|%$|~$|\.old$|SCCS|/core$|\.o$|\.orig$' >>Exclude
Recursively change the owner to "ec2-user" and group to "apache" of all files in "/vol/html"
sudo chown -R ec2-user:apache /vol/html
View lines 116 through 120 of history
history | head -n 120 | tail -n 5
Log in using key file "./device_id.pem" as user "deviceuser" on host "middle.example.org" and port 2222
ssh -i ./device_id.pem -p 2222 [email protected]
Find all empty folders in the current directory and below
find . -type d -empty
View history using "vim"
history | vim -
Shifts all positional arguments but last one, keeping it in $1 variable.
shift $()
Counts lines in each *.cpp, *.c, *.h file.
wc -l `find . -type f \( -name "*.cpp" -o -name "*.c" -o -name "*.h" \) -print`
Search all of /usr for any directory named 'My Files', for each directory found, copy it to /iscsi preserving full paths and attributes, then remove it.
find /usr -type d -name 'My Files' -exec rsync -avR '{}' /iscsi \; -exec rm -rf '{}'\;
Find all files under current directory that were modified more than 7 days ago and delete them
find . -type f -mtime +7 -print0 | xargs -0 rm
Force create a symbolic link named "$pdir" to "$pluginpath" with verbose output
sudo ln --symbolic --verbose --force "$pluginpath" "$pdir"
Prints day of first Tuesday in a month.
cal | awk 'NR==2 {for {sub;a[$i]=i}} NR>2 {if {printf "%02d\n",$a["Tu"];exit}}' FIELDWIDTHS="3 3 3 3 3 3 3 3"
Find smallest file in the current directory with find commad
find . -type f -printf "%s\t%p\n" | sort -n |head -1
Print the 10 most used commands
history | awk '{print $2}' | awk 'BEGIN {FS="|"}{print $1}' | sort | uniq -c | sort -n | tail | sort -nr
Disable jobs running in their own process group in the shell
set +m
Remove all .tmp files in and below /tmp
find /tmp -name "*.tmp" -print0 | xargs -0 rm
find all data files in current folder which have not been changed in the last 60 minutes and display their name without extension
find . -iregex "./[^/]+\.dat" -type f -cmin +60 -exec basename {} \;
Removes all files like 'A*.pdf' from current folder without prompting.
rm -f A*.pdf
List files under current directory according to their size in descending order
find . -type f -exec ls -s {} \; | sort -n -r
Save a list of all the files/directories under current directory tree to a file named 'foo'
find . -fprint foo
Search the current directory tree for files and directories whose names do not end in ".exe" and ".dll"
find . ! \
Unzip "file.gz" and print each line with the 5th " or | separated field greater than 5
zcat file.gz | awk -F'[|"]' '$5>5'
Decompress ${set1[@]} files with gzip
gzip -d ${set1[@]} &
Find all files with '.txt' extension under '/home/my_dir' dirctory tree and display the number of lines in these files
find /home/my_dir -name '*.txt' | xargs grep -c ^.*
change the permission of all php files in current folder. Plus symbol at the end is used to give multiple files as input to the chmod command
find . -name "*.php" -exec chmod 755 {} +
Find all files named 'Makefile' in the /usr/ports directory tree and count the number of lines in them matching regular expression '^MASTER_SITE_SUBDIR.*\.\./.*authors'
find /usr/ports/ -name Makefile -exec grep '^MASTER_SITE_SUBDIR.*\.\./.*authors' '{}' '+' | wc -l
List files and directories one level deep in the current directory tree
tree -L 2
Verbosely compresses all files on third and fourth depth level keeping original files in place.
bzip2 -kv */*/*
print the last word in a.txt
tac a.txt | awk 'NF{print $NF; exit}'
Split "data.csv" into files with at most 100 lines each and using a prefix "data_" and numeric suffixes starting with 1 and ending with ".csv"
split --numeric-suffixes=1 --additional-suffix=.csv -l100 data.csv data_
Serach in current directory downwards all files which have not been modified since last 7 days
find . -mtime +7 -print
Find regular files named "expression -or expression" under and below /dir/to/search/
find /dir/to/search/ -type f -name 'expression -or expression' -print
Decompress "path/to/test/file.gz" to standard output and save all lines matching "my regex" to files with a 1000000 line limit
gzip -dc path/to/test/file.gz | grep -P --regexp='my regex' | split -dl1000000 - file
Counts non-empty lines in file fileName.
cat fileName | grep -v ^$ | wc -l
Prints long recursive listing of all content of a current folder, saving output to 'output.file'.
ls |& tee files.txt
Find all directories named essbase under /fss/fin
find /fss/fin -type d -name "essbase" -print
Create an empty file with a carriage return character in its name.
echo -e "Icon\\r" | xargs touch
find all the files that have been modified in the last 2 day
find -daystart -mitime -1
Find all directories under mydir
find mydir -type d
Find all files/directories that start with 'readme' in their names under '/usr/share/doc' directory tree
find /usr/share/doc -name '[Rr][Ee][Aa][Dd][Mm][Ee]*'
List environment variables whose name matches ".*X.*"
set | awk -F "=" '{print $1}' | grep ".*X.*"
Find files/directories that have no owner or group under /path
find /path -nouser -or -nogroup
Print only digits in variable "$name"
echo $name | tr -c -d 0-9
find all the files in the entire filesystem which belong to the group root and display the ten files.
find / -group root | head
Find all the files which are changed in last 1 hour
find / -cmin -60
change the group to "new_group" and permissions to 770 for all the files in the current folder
find . -name "*" \
Print a welcome message with the current user's user name
echo -ne "Welcome $!\n"
Find "*prefs copy" files in the /mnt/zip directory tree and remove them with prompting
find /mnt/zip -name "*prefs copy" -print0 | xargs -p rm
Find files/directories under current directory and force xargs to print them one by one
find . | xargs -n 1 echo
run command "sh runProgram.sh" as user jetty
su - jetty -c sh runProgram.sh
Find all files named "file.ext" in the current directory tree and print the path names of the directories they are in
find `pwd` -name file.ext |xargs -l1 dirname
Print the lines in "table.txt" grouped by the first field
cat table.txt | awk '{print $1}' | sort | uniq | xargs -i grep {} table.txt
Search for files/directories with the case insensitive pattern anaconda.* in /var/log
find /var/log/ -iname anaconda.*
Print a list of regular files from directory tree sort_test/ sorted with LC_COLLATE=en_US.utf8
find sort_test/ -type f | env -i LC_COLLATE=en_US.utf8 sort
Run a "rm" process to recursively remove "cache", making it immune to all SIGHUP signals sent to it.
nohup rm -rf cache &
Find files/directories named 'articles.jpg' under current directory tree and change their permission to 644
find . -name "articles.jpg" -exec chmod 644 {} \;
Print common lines in file "a" and "b"
comm -12 < <
View the man page of find
man find
split the file hugefile.txt into pieces per 100000 lines named as partNNN with digital prefixes
split -a4 -d -l100000 hugefile.txt part.
Compress and display the gzipped filenames of every file on the system that is greater than 100000 bytes and ends in ".log"
sudo find / -xdev -type f -size +100000 -name "*.log" -exec gzip -v {} \; 2>&1 | awk '{print $6}'
Highlights current day in a month calendar with color.
cal -h | sed "s/ $ /"$'\033\[94m&\033\[0m/g; '"s/ $$/"$'\033\[94m&\033\[0m/g'
compare each C header file in or below the current directory with the file /tmp/master
find . -name '*.h' -execdir diff -u '{}' /tmp/master ';'
Search for the string 'git' in all the files under current directory tree excluding paths and names that contain the string 'git'
find . -not -path "*git*" -not -name '*git*' |grep git
Format file "list-of-entries.txt" as new-line separated columns
column -t -s $'\n' list-of-entries.txt
find all the files in the current folder and display adding quotations to each file
find . -exec echo -n '"{}" ' \;
Finds all users logged in via ssh.
w | grep ssh
Save the md5 sum of $twofish to variable 'twofish'
twofish=`echo -n $twofish | md5sum | tr -d " -"`
List all *.txt files/directories under /etc
find /etc -name "*.txt" | xargs ls -l
list regular file which file name end with 'cache' 'xml' or 'html' in current directory
find . -type f \( -name "*cache" -o -name "*xml" -o -name "*html" \)
Print the number of entries (files, directories, symlinks, etc.) in the subdirectories of the current directory, stopping search at any device mount points.
sudo find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n
Finds IP address of 'eth0' network interface.
ifconfig eth0 | grep 'inet addr:' | awk '{print $2}' | awk -F ':' '{print $2}'
Print all filenames under /proc and below
find /proc -print0 | xargs -0
find all .pm, .pl files in /users/tom and search for a pattern in these files and display the matched file names
find /usr/tom | egrep '*.pl| *.pm' | xargs cat | grep <PATTERN>
display all the files in the file system which are changed a minute ago
find / -newerct '1 minute ago' -print
Print base name of the file name without all extensions.
basename "$FILE" | cut -d'.' -f-1
Display the last colon-separated field of variable 'var'
echo "$var" | rev | cut -d: -f1 | rev
change permissions of files older than 30 days
find /path/to/directory -type f -mtime +30 -exec chmod 644 {} +
Print "$line" in hexadecimal 2-byte units
echo -n $line | od -x
Copies '[MacVim_source_folder]/src/MacVim/mvim' to the '/usr/local/bin', printing info message on each operation.
cp -v [MacVim_source_folder]/src/MacVim/mvim /usr/local/bin
Prints "$NEWFILE" to the terminal and file '/etc/timezone' as a root user.
echo "$NEWFILE" | sudo tee /etc/apt/sources.list
Search the current directory tree for symbolic links to files matching pattern '*/test*'
find -P . -lname '*/test*'
search for all the files in the current folder which have spaces and force delete them
find . -name "filename including space" -print0 | xargs -0 rm -rdf
Show manual page for the find utility
man find
Print the content of the file 'file' deleting the last four lines
nl -b a file | sort -k1,1nr | sed '1, 4 d' | sort -k1,1n | sed 's/^ *[0-9]*\t//'
Search the current directory tree for an html file having the text 'Web sites' in it
find . -type f -iname \*.html -exec grep -s "Web sites" {} \;
find all the pdf files in a folder which start with a specific name and display them in the sorted order of their time stamps
find "/path/to/pdfs/" -type f -name "$1*.pdf" -exec stat -f "%10Dm %SN" {}\; | sort -k1,1n -k2,2
Duplicate directory tree under /mnt/usr/lib to /usr but creating symlinks to files instead of copying them.
cp -rs /mnt/usr/lib /usr/
Search directory tree `MyApp.app' for directories whose name is 'Headers' and delete them suppressing error messages
find MyApp.app -name Headers -type d -exec rm -rf "{}" \; 2>/dev/null
Print 1 to 10 by separating them with colon
echo {1..9}: 10 | tr -d ' '
Find all files/directories under current directory and print them twice in each line
find | xargs -i sh -c "echo {} {}"
Print "file1.txt" "file2.txt" and "file3.txt" with filename headers
tail -n +1 file1.txt file2.txt file3.txt
kill all background processes
kill -INT $
Trim leading and trailing whitespace from variable 'var'.
var=`echo $var | awk '{gsub(/^ +| +$/,"")}1'`
Split "$INFILE" into files of at most "$SPLITLIMT" with a numeric suffix and a prefix "x_"
split -d -l $SPLITLIMT $INFILE x_