nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Count total number of lines in all *.txt file in cuuent directory .
find . -type f -name '*.txt' -exec wc -l {} \; | awk '{total += $1} END{print total}'
Create a symbolic link in the current directory for each file under the directories matching "../[12][0-9][0-9]"
find ../[12][0-9][0-9][0-9] -type f -exec ln -s {} \;
Find all directories under current directory and change their permission to 700
find . -type d -exec chmod 700 {} \;
Copy the 3 specified files to /tmp/package, preserving/creating directory structure of each file as specified on command line.
cp --parents src/prog.js images/icon.jpg /tmp/package
Print the contents of "file" in reverse order
nl file | sort -nr | cut -b8-
Display differences between files "a.txt" and "b.txt" side-by-side and do not output common lines.
diff -a --suppress-common-lines -y a.txt b.txt
displays all files in the current directory
find .
display all the regular/normal files in the home folder that have been modified in the last 1 day (from the start of day ie, from 00:00 )
find ~/ -daystart -type f -mtime 1
Print paths to all subdirectories inside of a directory
du | awk '{print $2}'
search for the directory testdir in the folder /home
find /home -type d -name testdir
Change permission to 755 for all directories under $d directory tree
find "$d/" -type d -print0 | xargs -0 chmod 755
prints absolute file path of a file
echo $(cd $ && pwd -P)/$
Find the sizes of only directories under current directory sorted by size and redirect the output to dir-sizes.txt
find . -type d -print0 | xargs -0 -n1 du -sk | sort -rn > dir-sizes.txt&
Change owner to "root" and group to "wheel" of "bin"
sudo chown root:wheel bin
Change permissions of all regular files from the current directory tree to 644
find . -type f -exec chmod 644 {} +
Find regular files which have 644 permission
find . -perm 644 -type f -exec ls -l {} \;
Report available space on the file system containing /tmp in kilobytes.
df -k /tmp | tail -1 | awk '{print $4}'
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
List all *.c, *.h and *.cpp files under current directory
find . -type f \ -exec ls {} \;
copy all the mp3 files from current folder to another folder
find . -name '*.mp3' -exec cp -a {} /path/to/copy/stuff/to \;
search for a word in all the files in the current directory and display the file paths relative to the current directory
find . -exec grep -l foo {} +
Puts working directory into clipboard, stripping newlines
echo -n $ | pbcopy
Force create a symbolic link named "mylink" with target "/apps/myapps/new/link/target"
ln -f -s /apps/myapps/new/link/target mylink
Search all files in the current directory tree for "SearchString", ignoring .html files and skipping .svn directories
find . \( -name '*.svn*' -prune -o ! -name '*.html' \) | xargs -d '\n' grep -Hd skip 'SearchString'
Remove all core dump files from user's home directory
find ~/ -name 'core*' -exec rm {} \;
Display each line in file.txt backwards
rev file.txt
Rename "/usr/bin/php" to "/usr/bin/~php"
sudo mv /usr/bin/php /usr/bin/~php
Search the current directory tree for regular files whose names match regular expression ".+-[0-9]+x[0-9]+\.jpg"
find . -type f -regex ".+-[0-9]+x[0-9]+\.jpg"
Remove trailing spaces, replace tabs with spaces, replace Windows CRLF with Unix LF in all *.java, *.xml and *.css files under current directory excluding ./vendor directory and its contents
find . -path ./vendor -prune -o \ -exec gsed -i -E 's/\t/ /' \{} \; -exec gsed -i -E 's/[[:space:]]*$//' \{} \; -exec gsed -i -E 's/\r\n/\n/' \{} \;
Find all 'test' directories in the current directory tree and remove them
find . -name test -type d -print0|xargs -0 rm -r --
Remove all files with '.js' extension from the 'js' directory tree
find ./js/ -type f -name "*.js" | xargs rm -f
change user and group of the file /usr/bin/aws to user amzadm and group root
chown amzadm.root /usr/bin/aws
Find all files and directories that do not match the pattern given as the $controlchars variable
find . ! -name "$controlchars"
search for all "tif" images in current folder
find . -name '*.tif ' -print
Enables shell option 'failglob'.
shopt -s failglob
Write "fifo forever" infinitely using the named pipe "fifo" by writing its contents to standard output and to "fifo"
echo "fifo forever" | cat - fifo | tee fifo
SSH into server "server.com" as user "remote_user"
Removes all cached yum data from a system.
sudo yum clean all
create directories bravo_dir and alpha_dir
mkdir bravo_dir alpha_dir
display all files in current folder, with each file name displayed twice on same line
find . | xargs -I{} printf "%s%s\n" {} {}
Find recursively all files whose names begin with "foo"
find . -name "foo*"
Find all files/directories named 'document' in maximum 4 levels down the '/usr' directory
find /usr -maxdepth 4 -name document -print
Display the host's ECDSA fingerprint using the md5 hasing algorithm.
ssh-keygen -l -E md5 -f /etc/ssh/ssh_host_ecdsa_key.pub
Set 644 permission to all regular files under current directory
chmod 644 `find -type f`
Prints process tree with command line arguments of a process having id $PID.
pstree -a "$PID"
Find recursively all files whose names ends with "foo"
find . -name "*foo"
Finds string beginning with 'IFS' in a 'set' output.
set | grep ^IFS=
Search for 'some string' in all *.axvw files under current directory and show the matched lines with line numbers
find . -name '*.axvw' -print0 | xargs -0 grep -n 'some string'
Print the files in the current directory as a list of comma separated values
ls | sed '$!s/$/,/' | tr -d '\n'
Set variable 'file' to the base name of first argument to script or function, that is the part following the last slash.
file=$( basename "$1" )
Search the /Path/bar* directories recursively for files matching pattern "file_name*"
find /Path/bar* -name "file_name*"
Read a line from standard input with a timeout of 10 seconds
read -t 10
Dump "file" as ASCII characters
od -t c file
Search the current directory recursively for text files containing at least one character
find -type f -exec grep -Iq . {} \; -and -print
Split "/usr/bin/firefox" into 1000 files of about equal size
split -n 1000 /usr/bin/firefox
Find all the files in entire file system which are modified 50 days back.
find / -mtime 50
Archive "/path/to/files/source" to "user@remoteip:/path/to/files/destination" via ssh on port 2121
rsync -azP -e "ssh -p 2121" /path/to/files/source user@remoteip:/path/to/files/destination
Find files that were modified in less than 1 minute ago
find / -mmin -1
Recursively copy "source", "dir", and "target" to "dir" as a dry run
rsync -rvc --delete --size-only --dry-run source dir target dir
Print the base name of the current working directory
pwd | xargs basename
Print all filenames under /proc and below
find /proc -exec ls '{}' \;
find all the php files
find -name '*.php'
find all the cpp(C++ source files), java, header files in the current directory
find . -name *.cpp -o -name *.h -o -name *.java
create a backup of all the files which have been modified in the last 48 hours
find source/directory -ctime -2 | cpio -pvdm /my/dest/directory
Rename all *.jpg files to *.jpg$.jpg files under current directory by appending the parent directory name at the beginning of their names
find . -name '*.jpg' -exec sh -c 'mv "$0" "$(basename $)-${0%.JPG}$.jpg"' {} \;
list *.bmp and *.txt files under the /home/user/Desktop directory.
find /home/user/Desktop -name '*.bmp' -o -name '*.txt'
Find all regular files with '.txt' extension excluding 'README.txt' files under current directory tree
find . -type f -name "*.txt" ! -name README.txt -print
Create a ssh tunnel on local port 2222 through "bridge.example.com" to "remote.example.com" port 22 without executing any commands and run in the background
ssh -N -L 2222:remote.example.com:22 bridge.example.com&
Execute "generate_commands" and run the resulting commands in the current shell.
source <
Find files that are empty
find -empty -type -f
Find files/directories under current directory and print them
find . -print0 | xargs -0 echo
Find all regular files under current directory tree, prepend '#' at the beginning of the lines that contain 'abc' in those files and modify them in-place
find . -type f -exec sed -i ‘s/.*abc.*/#&/’ {} \;
Find all files/directories named 'vimrc' in the entire filesystem
find / -name vimrc
Run 'chmod 0644' on all files in the current directory tree
find . -type f -exec chmod 0644 {} \;
Print the files to which symbolic links in the current directory point
find . -type l -print | xargs ls -ld | awk '{print $10}'
List recursively all files and directories in /var/www and pass the result to the `more' pager
find /var/www | more
Find all regular files in the current directory tree ignoring directory ./source/script
find . -path ./source/script -prune -o -type f -print;
Make 3 directories named "~/Labs/lab4a/folder" followed by the number 1, 2, or 3
mkdir ~/Labs/lab4a/folder{1..3}
remove all the pdf files in the current folder and do not delete those in the sub folders
find . -name "*.pdf" -maxdepth 1 -print0 | xargs -0 rm
Delete all broken symbolic links under '/usr/ports/packages' directory tree
find -L /usr/ports/packages -type l -exec rm -- {} +
Run script `fixname.sh' for each regular file from the current directory tree
find . -type f -exec sh fixname.sh {} \;
Processes file as binary file, and searches for symbol by its octal value '\015'.
grep -U -l $'\015' $
List regular files in current directory with read, write and execute permission for all users and also show the permissions
find . -type f -perm 777 -exec ls -l {} \;
List files under current directory according to their size in descending order
find . -type f -exec ls -s {} \; | sort -n -r
Find all regular files with permissions 777 under and below /home/user/demo/, and change their permissions to 755
find /home/user/demo -type f -perm 777 -print -exec chmod 755 {} \;
Unzip and expand tar archive "compressFileName"
zcat compressFileName | tar xvf -
find files under the current directory containing a space in the filename and delete them
find . -name "* *" -exec rm -f {} \;
get the job number from the stored PID
jobs -l | fgrep $! | perl -ne 'print "$1\n" if /\[\]/'
Find all files/directories that are owned by user 'wnj' and are newer than 'ttt' by modification time in the entire filesystem
find / -newer ttt -user wnj -print
change the ownership of all regular/normal files in the current directory
find . -type f -print0 | xargs -0 chown username
remove all the core files in the temp file after user confirmation
find /tmp -name core -type f -print0 | xargs -0 /bin/rm -i
List .c files in the current directory
find . \( ! -name . -prune \) -name "*.c" -print
Search for line 111 in file "active_record.rb" with 2 lines of context
nl -ba -nln active_record.rb | grep -C 2 '^111 '
search for the file "process.txt" in the current folder (case insensitive search)
find . -iname 'process.txt' -print
sort and 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 | sort -k1.8n -k1.1nr -k1
Find all the files without permission 777 in the file system
find / -type f ! -perm 777
Replace the "openssl" command executable with a symbolic link to "/usr/local/ssl/bin/openssl"
sudo ln -sf /usr/local/ssl/bin/openssl `which openssl`
Set variable PING to 1 if it's possible to ping host ADDRESS, to 0 otherwise.
PING=$
search for the directory "ora10" in the entire file system
find / -type d -name "ora10"
delete all the empty files in the current directory
find . -empty -exec rm {}\;