Ubuntu Commands

Basic Ubuntu Commands

sudo (superuser do)

sudo is used to run programs or other commands with administrative privileges.

Basic Syntax
  1. $sudo apt-get install openssh-server
apt-get (advanced packaging tool-get)

apt-get is used to install, update, upgrade and remove any packages.

Basic Syntax
  1. $sudo apt-get install openssh-server
ls (list)

ls is used to list all files and folders in your current working directory.

Basic Syntax
  1. $ls
cd (change directory)

cd is used to change the current working directory.

Basic Syntax
  1. $cd /etc
pwd (print working directory)

pwd is used to display the full pathname of the current working directory.

Basic Syntax
  1. $pwd
mkdir (make directory)

mkdir is used to create a new folder/directory into the current or any specified directory.

Basic Syntax
  1. $mkdir share
cp (copy)

cp is used to copy files and directories.

Basic Syntax
  1. $cp /source_path/source_filename /destination_path/destination_filename
mv (move)

mv is used to move files and directories from one location to another or to rename them.

Basic Syntax
  1. $mv /source_path/source_filename /destination_path/destination_filename
rm (remove)

rm is used permanently delete files and directories from current or any specified directory.

Basic Syntax
  1. $sudo rm /source_path/filename
rmdir

rmdir is used to delete empty directories. To remove a directory that contains files or subdirectories, you must use the rm command with the appropriate options i.e. -R means recurcive.

Basic Syntax

Deleting Empty Directories

$ rmdir directory_name

Example

$ rmdir tgsdir

Deleting Non-Empty Directories

$ rm -R directory_name

Example

$ rm -R tgsdir

chmod

chmod is used to modify file or directory permissions. There are two ways to change permissions. These are:

  1. With letters (symbolic method)
  2. With numbers (octal method)

If you do not own a file, you cannot change its permissions, use sudo for administrative right to modify the permissions on the same.

Basic Syntax

Symbolic Method

$chmod [options] filename

User Options
SymbolMeaning
uowner
ggroup
oothers
aall (same as ugo)
Permission Options
SymbolMeaning
rread
wwrite
xexecute

Operators
SymbolMeaning
+add permission
remove permission
=set exact permission

Octal Method

$chmod 666 filename

Permission Value
PermissionValue
r4
w2
x1

click for advanced level

Examples:

Add read + write for everyone (Octal Method)

$chmod 666 file.txt

Breakdown:

  • Owner → 6 (rw-)
  • Group → 6 (rw-)
  • Others → 6 (rw-)

Result:

-rw-rw-rw-

Remove write permission from group (Symbolic Method)

$chmod g-w file.txt

Add execute permission to owner (Symbolic Method)

$chmod u+x file1.txt

chown

chown is used to change the ownership of the file and folder. To change them, you usually need root (sudo) privileges.

Basic Syntax

$ sudo chown username filename

$ sudo chown -R username /path/foldername

Examples

Change ownership of file

$sudo chown vivek file.txt

Change ownership of folder

Changes owner of all files and folders inside /test by using -R

sudo chown -R vivek /test

click for advanced level

chgrp

chgrp is used to change the group ownership of file and folder. To change them, you usually needs a root (sudo) privileges.

Basic Syntax

$ sudo chgrp groupname filename

$ sudo chgrp -R groupname /path/foldername

click for advanced level

Examples

Change the group of file

$ sudo chgrp tgsgroup file.txt

Change the group of folder

Changes owner of all files and folders inside /test by using -R

$ sudo chggrp -R tgsgroup /path/test

passwd

passwd is used to change user password using terminal, to change a password admin rights required.

Basic Syntax
  1. $sudo passwd username
df (disk filesystem)

df is used to display the information about disk space usage or available on mounted filesystem.

Basic Syntax
  1. $df
  2. $df -h
du (disk usage)

du is used to estimate and display the disk space consumed by files and directories.

Basic Syntax
  1. $du
  2. $du -h
  3. $du -s
free

free is used to display the total amount of free and used physical memory and swap space in the system as well as the buffers anc cache used by kernel.

Basic Syntax
  1. $free
man

man is used to display a “manual page” that provides detailed information about command and their options.

Basic Syntax
  1. $man cp
–help

<command name> –help is used to display a brief usage summary and list of available options.

Basic Syntax
  1. $cp –help
info

info is used to provide more details or precise information.

Basic Syntax
  1. $info
top

top is a real-time system monitoring command that displays processor & other system resource activities.

Basic Syntax
  1. $top
whatis

whatis is used to show brief or one line description about the functionality of built-in command.

Basic Syntax
  1. $whatis cp
  2. $whatis fdisk
uname -a

uname-a is used to provide a wide range of basic information about the operating system.

Basic Syntax
  1. $uname -a

Click for Ubuntu Index

TGS's Chatbot AI Modelx
Chatbot