Skip to main content

Ubuntu/Unix Console Command -Cheat Sheet

Most popular Linux/Unix command those are required to know during working on Linux/Unix environment.

Primarily, when I started the work on ubuntu, I faced a common problem that was not familiar to know about the basic ubuntu command. After that, I aggregate basic commands and work very well.

Besides that, most of the time forgot the command and this helps me to cut-down googling time.


Privileges

SL

Command

Use / Description

1

sudo command

Run command as root

2

sudo -s

Open a root shell

3

sudo -s -u user

Open a shell as user

4

sudo -k

Forget sudo passwords

5

gksudo command

Visual sudo dialog (GNOME)

6

kdesudo command

visual sudo dialog (KDE)

7

sudo visudo

edit /etc/sudoers

8

gksudo nautilus

root file manager (GNOME)

9

kdesudo konqueror

root file manager (KDE)

10

passwd

change your password

 

File Commands

SL

Command

Use / Description

1

ls

Directory listing

2

ls -al

Formatted listing with hidden files

3

cd dir

Change directory to dir

4

cd

Change to home

5

pwd

show current directory

6

mkdir dir

create a directory dir

7

rm file

delete file

8

rm -r dir

delete directory dir

9

rm -f file

force remove file

10

rm -rf dir

force remove directory dir *

11

cp file1 file2

copy file1 to file2

12

cp -r dir1 dir2

copy dir1 to dir2; create dir2 if it doesn't exist

13

mv file1 file2

rename or move file1 to file2 if file2 is an existing directory, moves file1 into directory file2

14

ln -s file link

create symbolic link link to file

15

touch file

create or update file

16

cat > file

places standard input into file

17

more file

output the contents of file

18

head file

output the first 10 lines of file

19

tail file

output the last 10 lines of file

20

tail -f file

output the contents of file as it grows, starting with the last 10 lines Process Management


Process Management

SL

Command

Use / Description

1

ps

display your currently active processes

2

top

display all running processes

3

kill pid

kill process id PID

4

killall proc

kill all processes named proc *

5

bg

lists stopped or background jobs; resume a stopped job in the background

6

fg

brings the most recent job to the foreground

7

fg n

brings job n to the foreground


File Permissions

SL

Command

Use / Description

1

chmod octal file

– change the permissions of file to octal, which can be found separately for user, group, and world by adding:
● 4 – read (r)
● 2 – write (w)
● 1 – execute (x)

2

chmod 777

read, write, execute for all

3

chmod 755

rwx for owner, rx for group and world For more options

 

Firewall

SL

Command

Use / Description

1

ufw enable

turn on the firewall

2

ufw disable

turn off the firewall

3

ufw default allow

allow all connections bydefault

4

ufw default deny

drop all connections by default

5

ufw status

current status and rules

6

ufw allow port

allow traffic on port

7

ufw deny port

block port

8

ufw deny from ip

block ip adress

 

Installation

SL

Command

Use / Description

1

dpkg -i pkg.deb

install a package (Debian)

2

rpm -Uvh pkg.rpm

install a package (RPM)

 

Shortcuts

SL

Command

Use / Description

1

Ctrl+C

Halts the current command

2

Ctrl+Z

stops the current command, resume with fg in the foreground or bg in the background

3

Ctrl+D

log out of the current session, similar to exit

4

Ctrl+W

erases one word in the current line

5

Ctrl+U

erases the whole line

6

Ctrl+R

type to bring up a recent command

7

!!

repeats the last command

8

exit

log out of the current session

 

Package Management

SL

Command

Use / Description

1

apt-get update

refresh available updates

2

apt-get upgrade

upgrade all packages

3

apt-get dist-upgrade

upgrade with package replacements; upgrade Ubuntu version

4

apt-get install pkg

install pkg

5

apt-get purge pkg

uninstall pkg

6

apt-get autoremove

remove obsolete packages

7

apt-get -f install

try to fix broken packages

8

dpkg --configure -a

try to fix broken packages

9

dpkg -i pkg.deb

install file pkg.deb

10

(file) /etc/apt/sources.list

APT repository list

 

SSH

SL

Command

Use / Description

1

ssh user@host

connect to host as a user

2

ssh -p port user@host

connect to host on a port as user

3

ssh-copy-id user@host

add your key to host for the user to enable a keyed or passwordless login


System Info

SL

Command

Use / Description

1

date

show the current date and time

2

cal

show this month's calendar

3

uptime

show current uptime

4

w

display who is online

5

whoami

who you are logged in as

6

finger user

display information about the user

7

uname -a

show kernel information

8

cat /proc/cpuinfo

CPU information

9

cat /proc/meminfo

memory information

10

man command

show the manual for command

11

df

show disk usage

12

du

show directory space usage

13

free

show memory and swap usage

14

whereis app

show possible locations of app

15

which app

Show which app will be run by default

 

Compression

SL

Command

Use / Description

1

tar cf file.tar files

create a tar named file.tar containing files

2

tar xf file.tar

extract the files from file.tar

3

tar czf file.tar.gz files

create a tar with Gzip compression

4

tar xzf file.tar.gz

extract a tar using Gzip

5

tar cjf file.tar.bz2

create a tar with Bzip2 compression

6

tar xjf file.tar.bz2

extract a tar using Bzip2

7

gzip file

compresses file and renames it to file.gz

8

gzip -d file.gz

decompresses file.gz back to file


Network

SL

Command

Use / Description

1

ping host

ping host and output results

2

whois domain

get whois information for the domain

3

dig domain

get DNS information for the domain

4

dig -x host

reverse lookup host

5

wget file

download file

6

wget -c file

continue a stopped download

7

ifconfig

show network information

8

iwconfig

show wireless information

9

sudo iwlist scan

scan for wireless networks

10

sudo /etc/init.d/networking restart

resetnetwork for manual configurations

11

(file) /etc/network/interfaces

manual configuration

12

ifup interface

bring interface online

13

ifdown interface

disable interface

 

Searching

SL

Command

Use / Description

1

grep pattern files

Search for a pattern in files

2

grep -r pattern dir

Search recursively for a pattern in dir

3

command | grep pattern

Search for a pattern in the output of the command

4

locate file

find all instances of file

 

Helpful command

SL

Command

Use / Description

1

clear  

Clear the screen

2

whoami         

List who is logged in the session

3

echo string

Copies string to a terminal

4

date

List the current date and time

5

cal

Display a calendar

6

whereis command

Displays a command’s location in the directory structure

7

who

List currently logged in users

8

startx

Goes from command mode to graphical mode

 


Comments

Popular posts from this blog

What is RDBMS?

In our crucial programming world, RDBMS is stand for Relational Database Management Systems is based on the Relational Model that maintain data records and index in tables. Generally, the term "Relations" are maintained in RDMS.  In a relational database,store the data into collection of tables, which might be related by common fields (database table columns). RDBMS also provide relational operators to manipulate the data stored into the database tables. Most RDBMS use SQL as database query language. There are several objects are included in RDBMS like ,Indexes,Synonyms,Tables,Views Clusters,Constraints,Database links,Database triggers. Most popular RDBMS  are Oracle, MS-SqlServer, MySql,DB2. etc.

What are the difference between DDL, DML , DCL and TCL commands?

Database Command Types DDL Data Definition Language  (DDL) statements are used to define the database structure or schema.  -           CREATE - to create objects in the database -           ALTER - alters the structure of the database -           DROP - delete objects from the database -           TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed -           COMMENT - add comments to the data dictionary -           RENAME - rename an object DML Data Manipulation Language  (DML) statements are used for managing data in database. DML commands are not auto-committed. It means changes made by DML command are not permanent to d...

Identify and Delete duplicate Records in SQL Server

      S cenario: I have accumulated data into SQL Server database from three different servers (oracle, O2 and oracle) for a financial reporting. After data accumulated , we found more duplicate rows; business requirement was to remove all duplicate rows because of final data will be import to another system. For this purpose, I want to write script to find out duplicate rows from my table. Finally, I want to delete only duplicate rows not original row. Original row means if i have total 2 rows those same or duplicate, so I want to delete only one row that is duplicate. Let’s go............................ Step 1: Create a student Table below Script: CREATE TABLE [Students] (     [ID] [int] NULL,     [Name] [varchar] ( 50 ) NULL,     [address] [varchar] ( 50 ) NULL,     [contact] [varchar] ( 50 ) NULL,     [email] [varchar] ( 50 ) NULL ...