nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Remove all regular non-hidden files modified more than 7 days ago and residing in the /tmp directory tree
find /tmp -type f -name '*' -mtime +7 -print0 | xargs -0 rm -f
display all the soft links in a folder which are not broken
find -L /target ! -type l
Find all 1.txt, 2.txt and 3.txt files under current directory and change the permission to 444
find . \ -print|xargs chmod 444
change user of the direct public_html to user owner and group nobody
chown owner:nobody public_html
Findx all files having text "texthere" recursively in a current folder, and prints only file names with matching strings.
find -type f -exec grep -l "texthere" {} +
Find all *.mpg files under current directory and run an ffmpeg command on each of them
find . -name "*.mpg" -type f -print0 | xargs -0 -I {} -n 1 -P 4 ffmpeg -i {} {}.mp4
Add read permission for 'other' for all files/directories named 'rc.conf' under current directory tree
find . -name "rc.conf" -exec chmod o+r '{}' \;
Set the 'xtrace' shell option
set -o xtrace
Print the names of all files in the home directory and its subdirectories recursively whose MIME type is video
find ~ -type f -exec file -i {} + | grep video
download contents of a website "https://get.scoop.sh"
curl -L https://get.scoop.sh
Find all xx* files/directories excluding 'xxx' files/directories under your home directory
find ~ -name 'xx*' -and -not -name 'xxx'
recursively change owner and group of the directory and all files into it to user root and group root
chown -R root:root /var/lib/jenkins
Delete all lines matching "pattern" in "filename"
sed -i '/pattern/d' filename
find all files in current folder which are bigger than 270MB and less than 300MB
find . -size +270M -size -300M
print disk usage of files or folders in current directory
du -sh *
display all the files in the folder a
find a
display the contents of all the regular files in the current folder and save the output to out.txt
find . -type f -print0 | xargs -0 cat > out.txt
Make directory "dir" and do not cause an error if it exists
mkdir -p dir
find all c, cpp files in current folder
find -regex '.*\.\(c\|cpp\)'
Find all *.tex regular files in maximum 2 levels down the current directory
find . -type f -maxdepth 2 -name "*.tex"
Open "charm" executable file in vim
sudo vim `which charm`
Split a file ADDRESSS_FILE into pieces per 20 lines named with prefix "temp_file_ and numeric suffixes
split -l20 ADDRESSS_FILE temp_file_
Read a line from standard input into variable "password" without echoing the input
read -s password
find all the regular/normal files in the /path folder and delete them
find /path -type f -exec rm '{}' \;
Create a symbolic link in directory "new" for each file in "original" directory tree
find original -type f -exec ln -s {} new/{} \;
Convert ";" separated list "luke;yoda;leila" to new line separated list
echo "luke;yoda;leila" | tr ";" "\n"
list all the drectories present in the current directory and do not search in the sub directories.
find -maxdepth 1 -type d
Get virtual private memory use of process
top -l 1 -s 0 -stats vprvt -pid 8631
display a long listing of all regular files in current folder which have been modified in the last 60 minutes
find . -mmin -60 -type f -exec ls -l {} \;
change the group to "new_group" and permissions to 770 for all the files in the current folder, $0 is the input to the sub shell i.e, the name of the file
find . -name "*" -exec sh -c 'chgrp -v new_group "$0" ; chmod -v 770 "$0"' {} \;
display all the regular/normal files in the current folder that are not accessed in the last 10 minutes
find . -type f -amin +10
Print the first line of "filename" as a hex dump of characters
head -n 1 filename | od -c
create a symbolic link named "$ORACLE_HOME/include" to file "/usr/include/oracle/11.2/client"
sudo ln -s /usr/include/oracle/11.2/client $ORACLE_HOME/include
Make directory and parents as needed for each unique mime type in the current directory
mkdir -p `file -b --mime-type *|uniq`
Print unique lines of sorted file "f1" compared to sorted file "f2"
comm -2 -3 f1 f2
Numberically sort content of file 'files', using for sorting part of second one of dash separated fields beginning from second letter.
cat files | sort -t- -k2,2 -n
Change owner to "root" and group to "www-data" of "/foobar/test_file"
sudo chown root:www-data /foobar/test_file
Print numbers from 1 to 5 without separating spaces and without a newline
seq 5 | awk '{printf "%s", $0}'
List all files under the current working directory last modified less than a day ago
find `pwd` -mtime -1 -type f -print
Find all TXT files in the current directory and copy them to directory "$HOME/newdir"
find "$HOME" -name '*.txt' -type f -print0 | xargs -0 cp -ut "$HOME/newdir"
display a long listing of all the xls or csv files in the entire file system
find / -type f \ -exec ls -l {} \;
Print which files differ in "folder1" and "folder2" excluding "node_modules" recursively, output in two columns, and paginate the output
diff -rqyl folder1 folder2 --exclude=node_modules
display the amount of disk space used by all the log files in the folder /usr/local/apache/logs/
find /usr/local/apache/logs/ -type f -name "*_log"|xargs du -csh
Find all files whose names begin with 'Makefile' in the /usr/ports directory tree and count how many of them contain 'QTDIR'
find /usr/ports/ -name Makefile\* -exec grep -l QTDIR '{}' '+' | wc -l
Remove all vmware-*.log files under current directory
find . -name vmware-*.log -delete
Find files on the system that are bigger than 20 megabytes
find / -type f -size +20M -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'
List all files in the current directory tree including those that may contain spaces in their names
find . -print0 | xargs -0 -l -i echo "{}";
get year-month-day from date
date +%Y-%m-%d
Search for all jpg images on the system and archive them
find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
ssh into localhost on port 10022
ssh -p 10022 localhost
search for all the c files in the current folder
find . -name \*.c -print
Find directories with permissions 777 and change them to 755 recursively
find /home -type d -perm 777 -print -exec chmod 755 {} \;
Recursively removes all files and folders like 'FILE-TO-FIND' from current folder.
find . -name "FILE-TO-FIND" -exec rm -rf {} \;
Create all directories in the path specified by variable $tempWork
mkdir -p $tempWork
Counts the number of lines in each *.cs file in a git repository.
wc -l $
Execute "ls -l" every 2 seconds
watch ls -l
Change the user and group of all files and directories under /var/www to www-data:www-data
find /var/www -print0 | xargs -0 chown www-data:www-data
Find all the files whose name is FindCommandExamples.txt in the current working directory
find /root -name FindCommandExamples.txt
Sort all directory names matching folder_* and go to the last one.
cd $(find . -maxdepth 1 -type d -name "folder_*" | sort -t_ -k2 -n -r | head -1)
Execute the `convert' command for every .jpg file in the current directory
find . -maxdepth 1 -name *.jpg -print -exec convert
Print the sizes and names of all TXT files from the current directory tree
find . -iname "*.txt" -exec du -b {} +
For each line which has a common first field in file1.csv and file2.txt, output the first 4 fields of file1.csv - both files must be sorted first.
join -o 1.1,1.2,1.3,1.4 -t, file1.csv file2.txt
List the unique tab delimited field number "$FIELD" in all files, prefix with the number of occurrences, sort from most frequent to least frequent
cut -f $FIELD * | sort| uniq -c |sort -nr
Find all *.css files under $DIR and print the lines matching the regex '\.ExampleClass.{/,/}' from those files
find ${DIR} -type f -name "*.css" -exec sed -n '/\.ExampleClass.{/,/}/p' \{\} \+
Find all .mp3 files with more then 10MB and delete them from root directory .
find / -type f -name *.mp3 -size +10M -exec rm {} \;
find all the files in the current folder which have been modified in the 10 minutes ago
find -mmin +15 -mmin -25
Save the list of all .py files under and below the current directory to output.txt
find . -name "*.py" -type f > output.txt
Print a randomly sorted list of numbers from 1 to 10 to file "/tmp/lst" and outputs "-------" followed by the reverse list to the screen
seq 1 10 | sort -R | tee /tmp/lst |cat <(cat /tmp/lst) <(echo '-------') | tac
find all files in the current directory whose size is 24 or 25 bytes.
find . -size -26c -size +23c -print
Change the permission to 0755 for all directories under current directory
find . -type d -exec chmod 0755 {} \;
search for files that are readable for everybody, have at least on write bit set but are not executable for anybody
find . -perm -444 -perm /222 ! -perm /111
Print info about all mounted file systems
df
Run mycommand in /tmp without changing the current shell's working directory
Change the permissions of all regular files whose names end with .mp3 in the directory tree /var/ftp/mp3
find /var/ftp/mp3 -name '*.mp3' -type f -exec chmod 644 {} \;
change group of the file /tmp/php_session to group daemon
chown -R :daemon /tmp/php_session
change the permissions of all the files ending with "fits" in the folder "/store/01" and save the output file names to a log file
find /store/01 -name "*.fits" -exec chmod -x+r {} \; -exec ls -l {} \; | tee ALL_FILES.LOG
Takes folder name of file $0, changes backslashes to forward ones and saves result in $basedir variable.
basedir=$(dirname "$")
find all class files or sh script files in the current folder
find . -type f \
Print command with PID 11383
ps | egrep 11383 | tr -s ' ' | cut -d ' ' -f 4
Remove containing directories and suffix ".wiki" from specified path, output the result.
basename /home/jsmith/base.wiki .wiki
display all the files in the current folder which have colon in their name
find . -name "*:*"
Prepend the reverse history number to the output of the history command with arguments "$@"
history "$@" | tac | nl | tac
find all the php files in current folder and search for multiple patterns in these files
find -name '*.php' -exec grep -li "fincken" {} + | xargs grep -l "TODO"
Source "lib/B" relative to the directory of the executing shell script, will fail if currently running script is not in PATH.
source "$( dirname "$" )/lib/B"
display all the empty files in current folder
find . -empty
display the contents of all the regular files in the current folder and save the output to out.txt
cat `find . -type f` > out.txt
search for all the files in the current folder which start with gen and end with bt2 and assign the output list to the variable var.
var="$"
Find all directories named 'local' in entire file system
find / -name local -type d
display a long list of all the files that are bigger than 10KB in current folder
find . -size +10k -exec ls -l {} \;
Find all regular files named 'whatever' under current directory tree excluding all paths that contain any hidden directory
find . \ -type f -name "whatever"
change owner of the files into directory "/mydir" with ".txt" extension to user root
find /mydir -type f -name "*.txt" -print0 | xargs -0 chown root $(mktemp)
check the type of files in the folder /usr/bin
find /usr/bin | xargs file
List all IP addresses assigned to current hostname, pausing for user interaction after each page.
more /etc/hosts | grep `hostname` | awk '{print $1}'
Prints what year it was 222 days ago
date --date="222 days ago" +"%Y"
Search the entire file system for any file that is writable by other.
find / – perm -0002
Archive the directory structure under current directory into /somewhereelse/whatever-dirsonly.tar
find . -type d |xargs tar rf /somewhereelse/whatever-dirsonly.tar --no-recursion
List and see contents of all abc.def files under the directories /ghi and /jkl
find /ghi /jkl -type f -name abc.def 2> /dev/null -exec ls {} \; -exec cat {} \;
search for files cart4 or cart5 or cart6 in the folder junk which is in home folder and delete it.
find ~/junk -name 'cart[4-6]' -exec rm {} \;
display all the files in the current folder which have been modified in the last 24 hours
find . -mtime -1 -print
find all the ogg files in the current directory which have the word "monfichier" in their name
find -name *monfichier*.ogg