nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
search for a pattern in all the files in the current folder
find . | xargs grep <string-to-find>
Execute `somecommand' on each file from the current directory tree with the environment variable f set to the filename
find . -exec env f={} somecommand \;
Gets IP address of first listed network interface in system.
ifconfig | grep -E "{3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d:
Set variable OS to the name of the operating system, ie. "Linux"
OS=`uname -s`
Search the directory given as variable $d for empty subdirectories
find "$d" -mindepth 1 -prune -empty
Save the list of *.html files in the current directory tree to html_files.txt
find . -type f -name "*.html" > html_files.txt
display top 11 files along with the last access date for all the files in the file system
find / -type f -printf "\n%AD %AT %p" | head -n 11
Change the ownership of all aluno1's files in the current directory and below to aluno2
find . -user aluno1 -exec chown aluno2 {}
Recursively removes all files like '*.pyc' in a current folder.
find . -name "*.pyc"|xargs rm -rf
Locate OGG files under the home directory larger than 100 megabytes
find $HOME -iname '*.ogg' -size +100M
displays all files in the current directory
find .
Set the 'verbose' shell option causing bash to print shell input lines as they are read
set -v
Print the names of all files and directories in the current directory tree
find .
find all the files in the home folder which end with ".tex"
find ~ -iname '*.tex'
Remove all *.m4a files in the current directory and its subdirectories
find . -type f -name '*.m4a' -exec bash -c 'rm "$0"' '{}' \;
Create intermediate directories as required directory{1..3} and subdirectory{1..3} and directories subsubdirectory1 and subsubdirectory2
mkdir -p directory{1..3}/subdirectory{1..3}/subsubdirectory{1..2}
Prints long recursive listing of all content of a root folder, appending output to 'output.file'.
ls -lR / | tee -a output.file
Print content of '1' file
$ cat 1
Display an infinite number of lines consisting of "y", until the user presses the Q key.
yes | cat | more
Search for 'example' in all regular files under current directory tree
find . -type f -print | xargs grep "example"
Start 'top' to monitor all processes with the default settings.
top
Log output of a command in screenlog.0 every 10 seconds
screen -d -m -L python test.py
Search the current directory tree for regular files modified within the past 24 hours whose names do not end with ".DS_Store"
find . -mtime -1 ! -name '.DS_Store' -type f -printf '%f\n'
Look for *log files in directories at most three levels down the directory tree
find / -maxdepth 3 -name "*log"
List all files in the current directory tree that were last modified yesterday or later
find -newermt yesterday -ls
Find all aliencoders.[0-9]+ files/directories under /home/jassi/ directory
find /home/jassi/ -name "aliencoders.[0-9]+"
Search for 'pattern_to_search' in all regular files with '.txt' extension under '/directory/containing/files' and show the matched lines along with filenames
find /directory/containing/files -type f -name "*.txt" -exec grep -H 'pattern_to_search' {} +
Copy "src" to "dest" if "src" is newer than "dest"
rsync -u src dest
find all files that do not have execute permission to all
find . -type d ! -perm -111
Find all directories under current directory excluding directories (along with their contents) that start with a . (dot) in their names
find -type d -a ! -name '.?*' -o ! -prune
Search the current directory tree for *bash* files printing them on a single line
find . -name "*bash*" | xargs
Find all files/directories under $1 which have at least write permission for their owner and set write permission for group for these files/directories
find $1 -perm -u+w -exec chmod g+w {} \;
Search the entire file hierarchy for files named zsh that exist on ext3 file systems and print out detailed information about the file while sending anything printed to stderr to /dev/null.
find / -fstype ext3 -name zsh -ls 2> /dev/null
Calculate the sum of the numbers in '/file/with/numbers'
cat /file/with/numbers | php -r '$s = 0; while { $e = fgets; if break; $s += $e; } echo $s;'
Search the home directory tree for regular files modified yesterday
find ~ -daystart -type f -mtime 1
Print all string from file 'file2.txt' matching pattern in file 'file1.txt'
grep "$(cat file1.txt)" file2.txt
Print each logged in user's full name
finger -l | grep "Name:" | cut -d ":" -f 3 | cut -c 2- | sort | uniq
Report file system containing path to /dir/inner_dir/ disk usage in kilobytes.
df -k /dir/inner_dir/
Display the last 3 characters of variable foo.
echo $foo | rev | cut -c1-3 | rev
Remove all broken symlinks from the /usr/ports/packages directory tree
find -L /usr/ports/packages -type l -delete
Recursively change the owner of all files in "/usr/local/lib/node_modules" to the current user
sudo chown -R $USER /usr/local/lib/node_modules
Find all regular files in the /path/to/base/dir tree
find /path/to/base/dir -type f
Expand bash array "myargs" as arguments to "mv"
mv "${myargs[@]}"
Archive file 'file' with bzip2 tool, store compressed data to a file 'logfile' and also print to screen
bzip2 -c file | tee -a logfile
Display inputfile all on one line (replace newlines by spaces)
awk '{printf "%s|", $0} END {printf "\n"}' inputfile
Prints long listing of content in a root folder, including hidden files, with human-readable sizes, and stores output to '/root/test.out' file.
ls -hal /root/ > /root/test.out
Find files owned by nonexistent users
find / -nouser -print
replaces the last occurrence of 'a' with 'c'
tac infile.txt | sed "s/a/c/; ta ; b ; :a ; N ; ba" | tac
Save the short system host name to variable "hostname"
hostname=`hostname -s`
Remove all files whose names start with spam-
find . -name 'spam-*' | xargs rm
list broken symbolic links under "somedir"
find "somedir" -type l -print0 | xargs -r0 file | grep "broken symbolic" | sed -e 's/^\|: *broken symbolic.*$/"/g'
Find all configration files in Home directory & Subtitute permanently in files
find $HOME -name "*.conf" -exec sed -i 's/vermin/pony/g' {} \;
Move all *.pdf.marker files and their corresponding *.pdf files under ${INPUT_LOCATION} to ${OUTPUT_LOCATION}
find ${INPUT_LOCATION} -name '*.pdf.marker' -exec sh -c 'mv $0 `dirname $0`/`basename $0 .marker` $1' {} ${OUTPUT_LOCATION} \;
Locate all files in the current directory and below that have "testfile" in their names
find -name "*testfile*"
Append all *.mp3 files modified within the last 180 days to tar archive `music.tar'
find . -name -type f '*.mp3' -mtime -180 -print0 | xargs -0 tar rvf music.tar
Create intermediate directoriy path2 as required and directories a..z
mkdir -p path2/{a..z}
find md5sum of 401
yosemite$ echo -n 401 | md5
Recursively counts non-blank, non-comment lines in all *.c files in a current folder.
find . -type f -name '*.c' -exec cat {} \; | sed '/^\s*#/d;/^\s*$/d;/^\s*\/\//d' | wc -l
Print the list of files in the current directory tree with "xx" preceding and following each filename
find . -exec echo xx{}xx \;
find all headers file *.h in /nas/projects directory
find /nas/projects -name "*.h"
Correct permissions for files in the web directory
find /your/webdir -type f | xargs chmod 644
Print out the contents of all *.txt files in the home directory
find ~ -name '*.txt' -print0 | xargs -0 cat
Search the regular files from directory tree 'directory_name' for "word" and print the names of the matched files
find directory_name -type f -print0 | xargs -0 grep -li word
find all the php files in the current folder
find . -name \*.php
Copy "/Users/username/path/on/machine/" to "[email protected]:/home/username/path/on/server/" and convert encoding from UTF-8-MAC to UTF-8
rsync --iconv=UTF-8-MAC,UTF-8 /Users/username/path/on/machine/ '[email protected]:/home/username/path/on/server/'
Unhide all hidden files in the current directory
find . -maxdepth 1 -type f -name '\.*' | sed -e 's,^\./\.,,' | sort | xargs -iname mv .name name
Show the files or directories in the current directory whose names are not "MyCProgram.c"
find -maxdepth 1 -not -iname "MyCProgram.c"
Execute all arguments to a shell script and write the output to console and "$FILE"
$@ | tee $FILE
find all files in the current folder which start with pro
find . -name pro\*
find all the files in the entire file system that have been modified between 50 to 100 days and display ten files
find / -mtime +50 -mtime -100 | head
display all the files in the current folder which end with ".bash"
find . -name "*.bash"
find all the files ending with undo in the current folder and calculate the total size of these files
find . -name "*.undo" -ls | awk '{total += $7} END {print total}'
display all the files in the current directory excluding those that are in the 'secret' directory
find . -name 'secret' -prune -o -print
Add read and execute permission to command "node"
sudo chmod +rx $
Make an archive of .txt files from the dir/ directory tree
find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > dir_txt.tar.bz2
display all file in the folder /dir/to/search except ".c" files
find /dir/to/search/ -not -name "*.c" -print
Set variable OS to the name of the operating system, ie. "Linux"
OS=$(uname -s)
Find all directories under minimum 1 level down the $GIVEN_DIR directory with null character as the delimiter
find "$GIVEN_DIR" -type d -mindepth 1 -print0
Exclude directory from find . command
find . -name '*.js' -and -not -path directory
print bindings for "p" and "e" with no case sensitivity
bind -p|grep -i '"[pE]"'
Search the current directory tree for files whose names end in "rb" or "js"
find . -regextype posix-egrep -regex ".*(rb|js)$"
Enables shell option 'lithist'.
shopt -s lithist
List in detail the regular files from the /somelocation/log_output directory tree that were last changed more than 40 days ago
find /somelocation/log_output -type f -ctime +40 -exec ls -l {} \;
Convert all characters in "$a" to upper case and save to variable "b"
b=`echo "$a" | sed 's/./\U&/g'`
Print the lines of file "strings" specified in file "index"
join < <
find all files under the current directory, filtering the output through a regular expression to find any lines that contain the word foo or bar.
find ./ | grep -E 'foo|bar'
Find UTF-8 files with BOM
find . -type f -print0 | xargs -0 awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'
Calculate the md5sum of the executable file of command 'c++'
md5sum `which c++`
dispaly a long listing of all the files in the current folder which have been modified in the last 14 days
find . -mtime -14 -ls
Add cron lists from "file1" and "file2" to list of cron jobs, giving errors for any lines that cannot be parsed by crontab.
cat file1 file2 | crontab
Change every directory under "/var/www/html/" to have permissions 775
sudo find /var/www/html/ -type d -exec chmod 775 {} \;
Retrieve only build number of current kernel, ie. #104
uname -v | grep -o '#[0-9]\+'
Find all the files in the current directory recursively whose permissions are 777
find . -type f -perm 0777 -print
Search the current directory tree for regular files whose names end in ".shtml" or ".css"
find . -type f \( -name "*.shtml" -or -name "*.css" \)
Find all *.java files under current directory and replace every occurrences of 'subdomainA.example.com' with 'subdomainB.example.com' in those files
find /home/www -name "*.java" -type f -print0 | xargs -0 sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g'
Find UTF-8 files with BOM
find . -type f -print0 | xargs -0 awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'
Prints random line from file $FILE.
sort --random-sort $FILE | head -n 1
Find files with name `aaa.txt' under the current directory
find . -name aaa.txt
Save hexadecimal byte 10 in binary file "file.moi" to variable "day"
day=$(od -t x1 --skip-bytes=9 --read-bytes=1 file.moi | head -1 | awk '{print $2}')
Make directories to "/some/path" as needed
mkdir -p ./some/path