nl_command
stringlengths
14
387
bash_code
stringlengths
0
532
Find "*.dat" files recursively in the current directory, print the lines starting on line 5 to the console and save to "concat.txt"
find . -type f \( -name "*.dat" \) -exec tail -n+5 -q "$file" {} + |tee concat.txt
display all directories in the current folder
find -type d
Delete all files in the current directory.
find . -exec /bin/rm {} \;
Pass a single argument containing a string of numbers from 1 to 100000 to "/bin/true"
/bin/true "$"
find all the directories in current folder and do not search in sub directories and create the same directory structure in another folder
find . -maxdepth 1 -type d -print0 |
Print line number of each line in /etc/passwd file, where current user name is found
cat /etc/passwd -n | grep `whoami` | cut -f1
Remount "/dev/shm" with a maximum size of "40G"
mount -o remount,size=40G /dev/shm
Search the current directory tree for files whose names do not end in ".exe" and ".dll"
find . -not -name "*.exe" -not -name "*.dll" -type f
delete all the empty files in the current directory
find . -empty -exec rm {}\;
Create intermediate directories ~/foo/bar/ as required and directories baz, bif, bang
mkdir -p ~/foo/bar/baz ~/foo/bar/bif ~/foo/boo/bang
Prints dates of $m month in $y year, preceded by month number and slash like ' 10/1'.
cal $m $y | sed -e '1,2d' -e 's/^/ /' -e "s/ \/ $m\/\1/g"
Search the /home/bozo/projects directory tree for files modified within the last 24 hours
find /home/bozo/projects -mtime 1
Create directorie 'some/path' as required in the current directory
mkdir -p ./some/path
Save the current date, system host name, and "$changes" with newlines removed to variable "subj"
subj="$ - $ - $"
create directory public_html into home directory
mkdir ~/public_html
find files in the current directory and sub-directories, that changed within last hour
find . -cmin -60
find all the files in the current folder which have been modified in the last 60 minutes, which are atleast 1 level deep and display a long listing of these files
find . -mindepth 1 -mmin -60 | xargs -r ls -ld
Find files whose names match the pattern given by the 2nd argument $2 of the Bash script and replace string $3 with $4 in them
find ./ -type f -name "$2" -exec sed -i "s/$3/$4/g" {} \;
Find files/directories under current directory that are modified exactly one hour ago
find . -mtime 1
Find all files/directories under current directory
find .
display all the regular/normal files in the current folder which have been modified after a specific time stamp and do not search in the sub directories
find -maxdepth 1 -type f newermt "$timestamp"'
change owner and group of the file it to user and group root
chown root:root it
Write "[some repository]" to standard output and append to "/etc/apt/sources.list" as root
echo "[some repository]" | sudo tee -a /etc/apt/sources.list
search for text files in the directory "/home/user1" and copy them to the directory /home/backup
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents
Number each line in "/etc/passwd" as right-justified zero padded to a width of 9
nl -nrz -w9 /etc/passwd
display all normal/regular files in current directory
find . -type f -print0
Find and remove multiple files such as *.mp3 or *.txt under current directory
find . -type f -name "*.mp3" -exec rm -f {} \;
Recursively search for all files not ending in ".xml" under the current directory, append ".xml" to the end of each file name
find . -type f \! -name '*.xml' -print0 | xargs -0 rename 's/$/.xml/'
Change directory to the download directory specified in the current user's user-dirs.dirs file
cd "$(grep DOWNLOAD $HOME/.config/user-dirs.dirs | cut -f 2 -d "=" | tr "\"" "\n")"
search for the file test2 in the current folder
find -name test2
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
Search for Subscription.java under current directory, and go to directory containing it.
cd "$(find . -name Subscription.java -printf '%h\n')"
Creates temporary directory with name formatted like .daemonXXXXXXX in /tmp/ folder, and saves path to it in 'TMPDIR' variable.
TMPDIR=$
Change permissions of all directories residing under and below ./debian to 755
find ./debian -type d | xargs chmod 755
Recursively finds all 'STATUS.txt' files containing text 'OPEN' and prints containing folder of them.
fgrep --include='STATUS.txt' -rl 'OPEN' | xargs -L 1 dirname
sort and display the unique lines display the contents of all the files that have been modified in the last 91 days and not in the last 2 days
find . -name "*.txt" -type f -daystart -mtime -91 -mtime +2 | xargs cat | sort | uniq
Print name of the file system containing $path.
df -h $path | cut -f 1 -d " " | tail -1
Find files in the current directory tree whose status was changed within the last 60 minutes
find . -cmin -60
Open "charm" executable file in vim
sudo vim `which charm`
Find recursively all Emacs backup files in the current directory and remove them
find . -name '*~' | xargs rm
Split "/tmp/files" into files of at most 1000 lines each
split /tmp/files
set alias "X2" for command "| cut -d' ' -f2"
alias -g X2="| cut -d' ' -f2"
Find user daniel's files of type jpeg
find . -user daniel -type f -name *.jpg
Download "http://www.multitran.ru/c/m.exe?CL=1&s=hello&l1=1" and convert encoding to "windows-1251" and print only printable characters
curl 'http://www.multitran.ru/c/m.exe?CL=1&s=hello&l1=1' | iconv -f windows-1251 | tr -dc '[:print:]'
Format the time string @133986838 according to the default time format and save it to variable 'VARIABLENAME'
VARIABLENAME=$
Find all files/directories under /path/to/dir/* paths and print the timestamp along with their paths and stat them
find /path/to/dir/* -printf "%T@|%p|%l" -exec stat -Lc "|%Y.0000000000" {} \;
Revert $string value and print first 20 space-separated fields
echo $string | rev | cut -d ' ' -f -20
Saves list of logged in users in system together with 'USER' header in the 'a' variable.
a=`w|cut -d' ' -f1`;
Find all files owned by user `comp'
find / -user comp
Print working directory separated by newlines instead of forward slashes
pwd | tr '/' '\n'
find all the directories with the name "some-dir" in the current folder and move them to another folder and do not search in subfolders
find ./ -maxdepth 1 -name "some-dir" -type d -print0 | xargs -0r mv -t x/
Counts the number of lines in each file but png|jpg|ico files in a git repository.
git ls-files | grep -vE "" | xargs wc -l
print all filenames of files under current dir containing 'foo', case-insensitive
find . -type f -exec grep -il 'foo' {} \;
find files which full path name like '*/*config' at current directory and print
find . -path '*/*config'
Find all files/directories in entire file system for which owner has at least read/write permissions, or the group has at least read permission, or others have at least read permission
find / -perm /u+rw,g+r,o+r
display all the normal/regular files in the current folder which are empty
find . -type f -empty
Read a line from standard input with prompt "Enter your choice: " and save response to variable "choice"
read -p "Enter your choice: " choice
Print the second space separated fields from standard input
tr -s ' ' | cut -d ' ' -f 2
Recursively changes group ownership of everything within a current directory to 'repogroup'.
chgrp -R repogroup .
download a file "http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip" using cookies "oraclelicense=accept-securebackup-cookie"
curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip
Remove files under /mnt/zip matching "*prets copy" with confirmation
find /mnt/zip -name "*prefs copy" -print0 | xargs -0 -p /bin/rm
Count the number of unique file extensions in the current directory tree
find . -type f | sed -e 's/.*\.//' | sed -e 's/.*\///' | sort | uniq -c | sort -rn
Find recursively all regular files in the current directory skipping hidden files and directories matching pattern '.?*'
find -name '.?*' -prune -o \
Print true directory name of the current directory
readlink `pwd`
Find all directories under minimum 2 levels down the mydir directory
find mydir -mindepth 2 -type d
delete all the text files in the current folder.
find . -type f -name "*.txt" -exec rm -f {} \;
Print content of each file under the current directory followed by that file name
find . -type f -exec cat {} \; -print
Find all files/directories 1 level down the current directory that are enlisted in file 1
comm -12 < <
Display human-readable file type description of ascii.txt
file ascii.txt
find all the files in the current folder which have executable permission to all the users and display the ten files
find . -perm /a=x | head
Represent current date in RFC 3339 format with precision to seconds and save it to 'timestamp' variable
timestamp=`date --rfc-3339=seconds`
Exit the shell immediately if an error is encountered
set -e
Search the xargstest/ directory recursively for files matching pattern 'file??'
find xargstest/ -name 'file??'
Print the /proc directory tree, ignoring the PID-process things
find /proc -type d | egrep -v '/proc/[0-9]*($|/)' | less
Execute `echo' for each file found
find . | xargs -n 1 echo
Create a symbolic link named ".profile" to "git-stuff/home/profile" without dereferencing ".profile"
ln -sn git-stuff/home/profile .profile
find all the text files in the current folder starting with "somefiles-"
find . -name "somefiles-*-.txt" -type f
Find all files/directories under current directory tree whose names start with 'test' followed by two digits and end with '.txt' extension
find . -regextype sed -regex "./test[0-9]\{2\}.txt"
Find files in the current directory tree that match "pattern" and run "git diff" on them
find . -name "pattern" | xargs git diff --
Copy default SSH public key to "somehost" as user "myname"
ssh-copy-id myname@somehost
Enables shell option 'nocaseglob'.
shopt -s nocaseglob
Archive current directory to "/some/path" on localhost, using ssh to authentify as user "me", only update files that are newer in the source directory.
rsync -auve "ssh -p 2222" . me@localhost:/some/path
Force create a hard link named '/home/user/Musik/youtube converted/aesthesys~ I Am Free, That Is Why I'"'"'m Lost..mp3' with target '/home/user/Musik/mix-2012-13/aesthesys~ I Am Free, That Is Why I'"'"'m Lost..mp3'
ln -f '/home/user/Musik/mix-2012-13/aesthesys~ I Am Free, That Is Why I'"'"'m Lost..mp3' '/home/user/Musik/youtube converted/aesthesys~ I Am Free, That Is Why I'"'"'m Lost..mp3'
Compare sorted files 'f1.txt' and 'f2.txt' and print in three columns strings unique for first file, second file, and common ones
comm < <
List all files/directories under current directory
find | perl -lne 'print quotemeta' | xargs ls -d
display all the files in the current folder which have the word "bills" in their name
find . -name '*bills*' -print
find all the html files in current folder and replace old string with new string
find . -name '*.html' -print0 | xargs -0 perl -pi -e 's/oldstring/newstring/g'
Send SIGTERM signal to first process sent to background by the current shell.
kill %1
Reports time consumed by command 'sleep 1' to the file time.txt together, and saves command error output to sleep.stderr.
{ time sleep 1 2> sleep.stderr ; } 2> time.txt
Print out the contents of all *.txt files in the home directory
find ~ -name '*.txt' -print0 | xargs -0 cat
Find all files/directories that were modified more than 2 days ago and redirect the list to ~/output.file
find . -mtime +2 | perl -pe 's{^}{\"};s{$}{\"}' > ~/output.file
Get the sizes of all files under dir2 directory
find dir2 ! -type d |xargs wc -c
Find all files in the current directory tree with size bigger than 5 MB and sort them by size
find ./ -size +5M -type f | xargs -r ls -Ssh
Copy local file "file" via ssh to remote "host" path "/directory/"
rsync -e ssh file host:/directory/.
Find all files recursively which end in ".php"
find . -name "*.php" -print
find all the html files in the current folder
find . -name "*.html"
find all the files in the folder /opt which have been modified between 20 to 50 days ago
find /opt -mtime +30 -mtime -50
Infinitely print "1" then "0"
yes 0 | sed '1~2s/0/1/'
Print 'file' content, formatting output as 29-symbol wide column, regarding space symbol as a word separator
cat file | fold -s -w29
Search the .sh files in the current directory tree for string "ksh"
find . -name "*.sh" | xargs grep "ksh"