sudo !!
ctrl + x + e
Add a space before command
ls -l
Fix command
fc
This will open last command in a file, you can edit that and exit. I will run the edited command
mkdir -p folder/{sub1,sub2}/{sub1,sub2,sub3}
# Above command will create 6 directories
# folder/sub1/sub1
# folder/sub1/sub2
# folder/sub1/sub3
# folder/sub2/sub1
# folder/sub2/sub2
# folder/sub2/sub3
# This also works with numbers also like
mkdir -p folder/{1..100}/{1..100}
# This will create 100*100 = 10,000 new directories, 1 to 100 directories and each directory it will have 1 to 100 sub directories
cat file.txt | tee -a log.txt | cat > /dev/null
# -a in command means append to log.txt
disown -a && exit # Disown all process then exit
rpm2cpio <package-name>.rpm | cpio -idmv
rpm2cpio php-5.1.4-1.esp1.x86_64.rpm | cpio -idmv
rpm -ql <package-name>
rpm -ql HSS
rpm -qlpv <package-name>.rpm
rpm -qlpv HSS-2.5.6.0.0-1.x86_64.elf6.rpm
semanage port -l | grep <process-name>
semanage port -l | grep http
Use gcc flags "-p -pg" for compiling and linking
top -b -n 1 -p <pid>
tar -tf <tar_name>
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes -v <program-to-run> <program-args>
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes -v ./hssStub -m Load
valgrind --tool=callgrind <program-to-run> <program-args>
callgrind_annotate --auto=yes callgrind.out.pid
# Other options
# --tree=both (prints, for each functions, their callers and the called functions)
# --threshold=100 (will print all the events)
export CVSROOT=:pserver:[email protected]:/home/lte_epc
- Generate public key
ssh-keygen
- Copy generated public key to destinations authorized key
cat /var/lib/jenkins/.ssh/id_rsa.pub | ssh [email protected] 'cat >> .ssh/authorized_keys'
rm -rf !(do_not_delete_this_file_or_directory)
rm -rf !(file1.txt|file2.txt)
For above command to work, we need to enable extended pattern matching in shell using below command
shopt -s extglob
w
Use -c option to print selected characters from each line
cut -c1 # Prints only first character of each line
cut -c 2,7 # Select 2nd and 7th characters
cut -c 2-7 # Select from 2nd to 7th character, both included
cut -c 2- # Select from 2nd char to end
cut -d$'\t' -f 1-3 # Cut with tab and select first 3 words(tab splitted)
curl wttr.in/delhi?lang=en
git config credential.helper store
grep -A 1 "some_text" <path> # Print 1 line after each search pattern
grep -B 1 "some_text" <path> # Print 1 line before each search pattern
grep -C 1 "some_text" <path> # Print 1 above and below search pattern
grep -c "some_text" <path> # Prints counts of search string in each file
grep -e "text_1" -e "text_2" # Print all lines having text_1 or text_2
grep -E '([0-9]) *\1' *
# -E to specify a regular expression
# * with \1 to search for 0 or 1 space
# \1 to search for same digit
# Last * for path
grep -rl myString . | xargs -o vim
vim `grep -rl myString .`
head -c10 # Print first 10 characters
tail -c10 # Print last 10 characters
sort -t $'\t' -k 2 # With with respect to second tab separated values
zip -r roster.zip roster.sql
unzip roster.zip
sed 's/old-string/new-string/g' # Globally replace all old with new string
sed 's/old/new/ig' # i, Ignore case
sed 's/old/new/2' # Replace only second instance
sed 's/str/{&}/g' # Enclose all occurrences of str in {}
awk '{print}' # Print everything
awk '{print $1 $2}' # Print only values from column 1 and 2
awk '/xyz/ {print}' # Print lines having string xyz
awk '{if($4 == "") print}' # Print columns whose 4th column is empty
awk '{if($2 >= 10 && $3 >= 10) print $0; else print $4}' # If-else
echo "10 + 20" | bc # Calculates to 30
bc filename.txt # filename has mathematical expressions
bc # Opens bc console
paste file1.txt file2.txt # Pastes each word from file1 and 2 column wise
paste -s file1.txt file2.txt # Paste all lines from 1 file at a time
paste -d "|" file1.txt # Use | as delimeter instead of tab(default).
paste file1.txt - - # Paste 2 consecutive lines
gdb --args <binary> <command line args>
gdb --args python -V # Run python binary with -V argument
Below command creates 2 files - domain.key has private key and domain.csr is certificate signing request file.
openssl req -newkey rsa:2048 -nodes -keyout domain.key -out domain.csr
openssl s_client -connect <hostname>:<port-number>
gio open <path to pdf file>
ab -k -c 2 -n 10 -s 60 http://example.com/
# -k, keep alive
# -c, concurrent connections
# -n, total number of requests to be sent
# -s, timeout in seconds for ab to complete analysis(by default it is 30)
- Art of command line: https://github.com/jlevy/the-art-of-command-line
- 8 shell commands: https://www.youtube.com/watch?v=Zuwa8zlfXSY
- Moving in CLI: https://clementc.github.io/blog/2018/01/25/moving_cli/
- TR command(Translates, deletes set of characters): https://www.geeksforgeeks.org/tr-command-unixlinux-examples/
- openssl commands: https://www.sslshopper.com/article-most-common-openssl-commands.html
- Block all domains: https://github.com/jmdugan/blocklists/blob/master/corporations/facebook/all