Vijayan
Vijayan Thanks for stopping by guys! I'm Vijayan and Techpulse is my beloved brainchild. Currently working as a PHP developer in a digital marketing start-up, I'm overly passionate about not just learning new things but also putting those into practice. I swear by a quote I once came across... 'What separates successful people from unsuccessful people is the former's ability to execute'. Feel free to reach out to me if you have any questions, suggestions or feedback. Hoping to see more of you here!

The most important Linux commands you need daily


The most important Linux commands you need daily

Use this guide to most important Linux commands, Utilities, and tools for beginners, enterprise administrators, and managers.

Directory Operations:

Command Description
pwd Show current directory
cd dir Change to directory dir
mkdir dir Create a new directory dir
rmdir dir Delete directory dir
ls dir List Contents directory dir

Example:

vijayan@vijayan-VPCCA35FA:~$ pwd
/home/vijayan
vijayan@vijayan-VPCCA35FA:~$ cd Downloads/
vijayan@vijayan-VPCCA35FA:~/Downloads$ mkdir techpulsetoday
vijayan@vijayan-VPCCA35FA:~/Downloads$ ls techpulsetoday
vijayan@vijayan-VPCCA35FA:~/Downloads$ rmdir techpulsetoday/

Special Directories:

Command Description
. Current Directory
.. Up a Directory
~ Home Directory
/ Root Directory
- Previous Directory

Example:

vijayan@vijayan-VPCCA35FA:~$ pwd
/home/vijayan
vijayan@vijayan-VPCCA35FA:~$ cd .
vijayan@vijayan-VPCCA35FA:~$ pwd
/home/vijayan
vijayan@vijayan-VPCCA35FA:~$ cd ..
vijayan@vijayan-VPCCA35FA:/home$ pwd
/home
vijayan@vijayan-VPCCA35FA:/home$ cd ~
vijayan@vijayan-VPCCA35FA:~$ pwd
/home/vijayan
vijayan@vijayan-VPCCA35FA:~$ cd /
vijayan@vijayan-VPCCA35FA:/$ pwd
/
vijayan@vijayan-VPCCA35FA:/$ cd -
/home/vijayan
vijayan@vijayan-VPCCA35FA:~$

ls Options:

Syntax:

ls [options] [file|dir]
Command Description
-a All inc. hidden file
-l Long Format
-i List file's inode index number
-t Sort by time & date
-d List directories  with ' */' [eg1. ls -d */ ][eg2. ls -d $PWD/* ]
-s List file size
-S Sort by time
-r Reverse order
-R Recursive
-X Sort by extension name

Example:

vijayan@vijayan-VPCCA35FA:~/Music/ringtone$ ls -lash
total 5.3M
4.0K drwxrwxr-x 2 vijayan vijayan 4.0K Jan  3 01:51 .
4.0K drwxr-xr-x 3 vijayan vijayan 4.0K Dec 31 22:53 ..
648K -rw-rw-r-- 1 vijayan vijayan 643K Dec 31 22:53 Aval Azhakai.mp3
564K -rw-rw-r-- 1 vijayan vijayan 557K Dec 31 22:54 Azhagiya Theeye.mp3
480K -rw-rw-r-- 1 vijayan vijayan 475K Dec 31 22:54 Azhagiya Theeye Whistle.mp3
680K -rw-rw-r-- 1 vijayan vijayan 675K Dec 31 22:55 Iru Vizhi unathu.mp3
624K -rw-rw-r-- 1 vijayan vijayan 617K Dec 31 22:55 Nenjai Poopoal.mp3
584K -rw-rw-r-- 1 vijayan vijayan 580K Dec 31 22:55 Pooppol Pooppol.mp3
540K -rw-rw-r-- 1 vijayan vijayan 536K Dec 31 22:55 Vaseegara Theme.mp3
620K -rw-rw-r-- 1 vijayan vijayan 613K Dec 31 22:55 Venmathi love fail.mp3
596K -rw-rw-r-- 1 vijayan vijayan 590K Dec 31 22:56 Verenna Verenna Male.mp3

File Operations:

Command Descriptions
touch file Create a new file
cp file1 file2 Copy file1 to file2
mv file1 file2 Move file1 to file2
rm file Delete a file
cat file Display content of a file
cat file1 file2 Cancatenate files
less file Display file (paginated), q to quit
head file Show first 10 lines
tail file Show last 10 lines [-n N →N lines; -f → Continuos update]

File Searching:

Command Descriptions
grep pattern file Searching for a line with a pattern in a file
grep -v Inverted search
grep -r Recursive search
grep -e pattern -e pattern Multiple patterns
locate file Quick search for a file
which cmd Find locations of binary
find dir -name pattern Find a file with a pattern in dir

Example:

grep -rnw '/var/www/html/' -e "techpulsetoday"

Standard IO Streams:

Command Descriptions
stdin Input typed on the command line
stdout Output on the screen
stderr Errors output on the screen
echo string Write a string to stdout

Example:

echo 'password' | sudo -S cp wp-config.php bkp-wp-config.php

Redirection:

Command Descriptions
cmd > file Output of cmd to file
cmd < file file used as input to cmd
cmd >> file Append output to file
cmd 2> file Write errors to file
cmd &> file Errors and stdout to file

Pipe Multiple Commands

Command Descriptions
cmd1 | cmd2 Stdout of cmd1 is used as input to cmd2
cmd1 | &cmd2 Stderr of cmd1 is used as input to cmd2
cmdpart1 \ cmdpart2 Continue command on next line
cmd1; cmd2 Execute cmd1 then cmd2

Processes:

Command Descriptions
ps Show processes of user
ps -e Show all processes
ps -fA Show all processes in detail
top Show all processes in real-time
cmd & Run command in the background
Ctrl-c Stop (kill) currently active process
Ctrl-z Suspend currently active process
bg Place suspended process in a background
fg Bring background process to foreground
kill pid Kill process with process id PID
Kill -9 pid Kill process PID (ungraceful)

Bash Shortcuts:

Command Descriptions
Ctrl-k Cut line of text
Ctrl-y Past line of text
Ctrl-e Go to end of line
Ctrl-a Go to start of line
TAB Autocomplete command/file
TAB-TAB Show list of possible autocompletes
up arrow Scroll previous commands
down arrow Scroll previous commands
histrory List recent commands
!! Repeat the last command
!N Execute command N from history
!abc:p Print the last command starting with abc
!abc Execute the last command starting with abc

Text file operation:

Command Descriptions
wc Line, word and character count
sort file Sort file, line by line
uniq file Display only unique lines of a file
sed ‘s/abc/def/g’ file Replace all occurrence of abc with def, out to stdout
cut -d “ “ -f N file Display field N of space delimited file
cut -d “,” -f M-N file Display field M-N of a comma delimited file

Tar Command:

Command Descriptions
-c Creates a new .tar archive file.
-x To untar or extract a tar file
-v Verbosely show the .tar file progress.
-f File name type of the archive file.
-z compressed gzip archive file
-r To add files or directories to existing tar archive file
-j To create a highly compressed tar file
-C untar in a different directory
-t viewing content of archive file
-W Verify an archive file

Example:

How to create a tar.gz file

To create a tar.gz archive from a given folder you can use the following command

tar -zcvf tar-archive-name.tar.gz source-folder-name

How to extract a tar.gz file

To extract a tar.gz compressed archive you can use the following command

tar -zxvf tar-archive-name.tar.gz

How to extract specific file(s) from tar.gz

tar -zxvf <tar filename> <file you want to extract>

Proper file Permissions for WordPress

sudo chown www-data:www-data -R *
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
sudo chmod 444 wp-config.php
sudo chmod 444 .htaccess

Three-digit permissions specified in octal

stat -c "%a %n" *

octal-three-digit-permissions

How to find recently modified files

see all files that were modified during the last 2 days

find . -mtime -2 -ls

How can I monitor the progress of an import of a large .sql file?

If you’re just importing from a dump file from the CLI on *nix, e.g.

mysql -uxxx -pxxx dbname < /sqlfile.sql

then first install pipe viewer on your OS then try something like this:

pv sqlfile.sql | mysql -uxxx -pxxxx dbname

How to convert ppk file from pem file?

Make sure puttygen installed on your computer. If it is not installed, type the below command,

sudo apt-get install putty-tools
puttygen keyfile.pem -O private -o avdev.ppk

How to download YouTube Playlist

The program ‘youtube-dl’ is currently not installed. You can install it by typing:

sudo apt install youtube-dl
youtube-dl -o '%(playlist)s/%(playlist_index)s - %(title)s.%(ext)s' https://www.youtube.com/playlist?list=PLtaXuX0nEZk9MKY_ClWcPkGtOEGyLTyCO

comments powered by Disqus