0% found this document useful (0 votes)
9 views13 pages

Linux Commands

The document provides information about common Linux commands and their usage. It lists several commands and their functions, options, and syntax. Some key commands covered include whoami, hostname, echo, man, pwd, cd, ls, clear, mkdir, rmdir, sudo, id, apt, wget, vi, cat, nano, touch, cp, mv, and rm.

Uploaded by

Ai Cha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views13 pages

Linux Commands

The document provides information about common Linux commands and their usage. It lists several commands and their functions, options, and syntax. Some key commands covered include whoami, hostname, echo, man, pwd, cd, ls, clear, mkdir, rmdir, sudo, id, apt, wget, vi, cat, nano, touch, cp, mv, and rm.

Uploaded by

Ai Cha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1.

Lab 1 / Lecture 1:

COMMAND USE OPTIONS SYNATX


whoami Prints the current / whoami
user's username
hostname Prints or sets the / hostname
system's hostname.
echo Prints the text / echo 'text'
followed after it.
man Displays the manual **-f, --whatis: Display a short man
pages for other description of the command. 'option'
commands, ==-k,== --apropos**: Search for command
providing commands related to a keyword.
documentation and
usage instructions.
pwd Displays the manual / pwd
pages for other
commands,
providing
documentation and
usage instructions.
cd Changes the current / cd
directory. 'Directory'
/ path
ls Lists directory -l: Long format listing, showing
contents. detailed information about files and
directories.
2. -a: Include hidden files (those
starting with a dot) in the listing.
3. -h: Human-readable file sizes,
displaying file sizes in a more
understandable format
4. -t: Sort files by modification time,
with the newest first.
5. -r: ==Reverse the order of the
listing.
6. -R:== Recursively list
subdirectories encountered.
7. -F: ==Append indicators to entries
to indicate file types (e.g., '/' for
directories)
COMMAND USE OPTIONS SYNATX
8. --color: Enable colorized output to
highlight different types of files.
9. -i:== Include inode number in the
listing.
==10. -s: ==Display the allocated
size of each file, in blocks.
clear Clears the terminal /
screen.
mkdir Creates a new - -p, --parents: This tells mkdir to
directory. create any missing parent directories
along the way. This is helpful when
creating nested directory structures.

- -v, --verbose: This makes mkdir


print a message for each directory it
successfully creates.

- -m, --mode=MODE: This option


allows you to set the permission
mode for the newly created
directories. You can specify the
permissions using a symbolic
notation.

- --help: This displays the help


message for the mkdir command,
explaining all available options and
usage.
rmdir Removes a directory (same options of mkdir except -m
(if empty). plus : )
- --ignore-fail-on-non-empty: By
default, rmdir fails if the directory
isn't empty. This option skips errors
for non-empty directories.
synaptic& A graphical package
(requires management tool
sudo or used in some Linux
admin) distributions to
manage
software packages.
sudo Allows users to run /
programs with the
security privileges of
COMMAND USE OPTIONS SYNATX
another user, typically
the superuser.
sudo su switches to super /
(root) user mode.
id Displays the user /
and group IDs of the
current user.
apt Advanced Package /
Tool, used for
package
management on
Debian-based
systems.
apt install Adds new programs /
to your system.
apt upgrade Updates all existing
programs to the
latest versions.
apt remove Deletes programs
from your system.
apt update Checks for new
versions of
programs, but
doesn't install them.
wget Downloads files from 1. -O : Save downloaded content to
the internet. a specified file.
2. quiet : Turn off output messages
(quiet mode).
3. -r, --recursive : Download
recursively, following links.
vi A text editor with /
powerful editing
capabilities.
cat displays the content /
of a file.
nano A simple text editor /
commonly used in
terminal
environments.
COMMAND USE OPTIONS SYNATX
apt upgrade Updates all existing
programs to the
latest versions.
apt remove Deletes programs
from your system.
apt update Checks for new
versions of
programs, but
doesn't install them.
wget Downloads files from 1. -O : Save downloaded content to
the internet. a specified file.
2. quiet : Turn off output messages
(quiet mode).
3. -r, --recursive : Download
recursively, following links.
vi A text editor with /
powerful editing
capabilities.
cat displays the content /
of a file.
nano A simple text editor /
commonly used in
terminal
environments.

2. LAB2 / Lecture2 :

COMMAND USAGE OPTIONS SYNTAX


touch Creates an empty /
file or updates the
access and
modification times
of a file.
cp Copies files or - -r, --recursive: Copies the contents of a
directories. source directory, including all subdirectories
and files, to the destination.
mv Moves or - -i, --interactive: Prompts for confirmation
renames files or before overwriting existing files in the
directories. destination.
- -f, --force: Overwrites existing files in the
destination without prompting.
COMMAND USAGE OPTIONS SYNTAX
- -v, --verbose: Shows messages about each
file being moved/renamed.
- -u, --update: Moves only if the source is
newer than the destination (or the destination
doesn't exist).
rm Removes - -i, --interactive: Prompts for confirmation
(deletes) files or before deleting each file. (Highly
directories. recommended for safety)
- -f, --force: Ignores nonexistent files and
avoids prompting before deletion. Use with
caution!
- -r, --recursive: Removes directories and
their entire contents (subdirectories and files
within).
- -v, --verbose: Prints messages about each
file being deleted.
- -W, --no-warranty: Disables prompting
entirely. Avoid using this unless you're
absolutely certain about what you're deleting.
(Not recommended for most users)
?/. reaplaces any /
single character.
; Separates /
multiple
commands on a
single line.
&& Executes the next /
command only if
the previous
command
succeeds.
cat Concatenates /
and displays files'
content.
> Redirects /
command output
to a file,
overwriting the
file's contents.
>> Appends output /
to a file.
COMMAND USAGE OPTIONS SYNTAX
< Redirects input /
from a file to a
command.
<< pass multiple /
lines of input to a
command or
script.
grep Searches for 1. -i Ignore case distinctions in both the
patterns in files or pattern and input files.
input streams.
2. -r Recursively search subdirectories
listed.

3. -n Prefix each line of output with the 1-


based line number within its input file.

4. -v Invert the sense of matching, to select


non-matching lines.

5. -w : Select only those lines containing


matches that form whole words.

6. -l : Suppress normal output; instead,


print the name of each input file from which
output would normally have been printed.

7. -c : Suppress normal output; instead,


print a count of matching lines for each input
file.

8. -E : Interpret pattern as an extended


regular expression (ERE, not the default
basic regular expression, BRE).

9. -F : Interpret pattern as a list of fixed


strings, separated by newlines, any of which
is to be matched.

10. -A : Print NUM lines of trailing context


after matching lines.

11. -B : Print NUM lines of leading context


before matching lines.
COMMAND USAGE OPTIONS SYNTAX

12. -m or --max-count=NUM : Stop reading a


file after NUM matching lines.
head Outputs the first /
part of files.
tail Outputs the last /
part of files.
wc Counts lines, - -c, --bytes: This option instructs wc to
words, and count and display the number of bytes in the
characters in a file.
file or input
stream. - -m, --chars: Similar to -c , this option tells
wc to count and display the number of
characters in the file. By default, wc
considers newline characters as well.

- -l, --lines: This is a commonly used option


that tells wc to count and display the number
of lines in the file.

- -w, --words: This option instructs wc to


count and display the number of words in the
file. It typically considers whitespace
characters like spaces or tabs as word
separators.
less A paginator for 1. Scrolling:
viewing text files,
allowing scrolling - Move forward one line: Press the ↓ key
and searching or the j key.
- Move backward one line: Press the ↑
key or the k key.
- Move forward one page: Press the
SPACE bar or the f key.
- Move backward one page: Press the b
key.
- Go to the beginning of the file: Press the
g key.
- Go to the end of the file: Press the G key.
2. Searching:

- Search forward: Press the / key


followed by the search term and then press
ENTER .
- Search backward: Press the ? key
COMMAND USAGE OPTIONS SYNTAX
followed by the search term and then press
ENTER .

- Repeat search: Press n to repeat the


search in the same direction, or N to repeat
the search in the opposite direction.

3. Display Line Numbers: You can display


line numbers by using the -N option:
less -N filename

4. Other Options:

- You can also pass multiple filenames to


less to view multiple files consecutively.

- Use the -R option to view files with ANSI


color escape sequences.

- Use the -i option to ignore case in


searches.

- Use the --help option for more


information about additional options.
sed #Replace "old" with "new" in file.txt and
save changes to the same file :
sed -i 's/old/new/' file.txt

# Perform multiple editing commands


using a script file

sed -f script.sed input.txt

# Apply sed commands from the


command line
sed -e 's/pattern/replacement/g' -e
'/^$/d' file.txt

# Suppress automatic printing of pattern


space
sed -n '1,5p' file.txt

# Enable extended regular expressions


sed -r 's/\b([0-9]{3})\b/\1-555-1234/'
file.txt
COMMAND USAGE OPTIONS SYNTAX
(- "s/old/new/" replaces the first occurrence of
"old" with "new" on each line.
- "script.sed" contains multiple sed
commands separated by newlines.
- "-n" suppresses automatic printing of
pattern space.
- "-r" enables extended regular expressions
for more complex pattern matching.)
du Displays the disk /
space used by
files and
directories.
gzip Compresses files /
using the gzip
compression
algorithm.
gunzip Decompresses /
gzip-compressed
files.
tar Manipulates - -c, --create: Creates a new archive file.
archives in the tar
format. - -x, --extract, --get: Extracts files from an
existing archive.

- -t, --list: Lists the contents of an archive


without extracting them.

- -r, --append: Adds files to an existing


archive.
- -u, --update: Updates an existing archive
by adding newer files or replacing older ones.

- -f, --file=ARCHIVE: Specifies


the name of the archive file to create, extract
from, or list.
-v, --
verbose: Provides detailed information about
the operation being performed (filenames,
progress, etc.).
type Indicates how a /
command name
is interpreted.
COMMAND USAGE OPTIONS SYNTAX
help Provides help for /
shell built-in
commands.
--help Displays detailed /
information about
a specific
command.
apropos Searches the /
manual page
names and
descriptions for a
specified keyword.
whatis provides a /
concise
description of a
specific command
or topic.
info provides access /
to detailed
documentation
about various
commands,
programs, and
topics.

3. *Lab 3 / Lecture 3:**

COMMAND USAGE OPTIONS SYNTAX


alias Creates shortcuts for
commands or command
sequences.
unalias Removes aliases
previously set with the
'alias' command.
sort Sorts lines of text files.
cut Extracts sections from
each line of files.
finger Displays user information,
including login name, real
name, shell, etc.
COMMAND USAGE OPTIONS SYNTAX
usermod used to modify user 1. -l, --login NEW_LOGIN:
account attributes. Change the username of the user
from its current value to
NEW_LOGIN.

2. -u, --uid UID : Set the user's


numerical user ID (UID) to UID.

3. -g, --gid GROUP : Change the


user's primary group to GROUP.

4. -d, --home HOME_DIR: Set


the user's new login directory to
HOME_DIR.

5. -s, --shell SHELL: Set the


user's login shell to SHELL.

6. -e, --expiredate
EXPIRE_DATE : Set the expiration
date of the user account to
EXPIRE_DATE.

7. -c, --comment COMMENT : Add


or change the value of the user's
description (or "GECOS" field).

8. -L, --lock : Lock the user's


password by putting a "!" in front
of the encrypted password in the
/etc/shadow file.

9. -U, --unlock : Unlock the


user's password, removing the "!"
in front of the encrypted password
in the /etc/shadow file.

10. -p, --password PASSWORD :


Set the user's password to the
specified encrypted password.
chfn Changes the user's full
name information.
chsh Changes the user's login
shell.
COMMAND USAGE OPTIONS SYNTAX
df Displays disk space usage
of filesystems.
export Sets environment variables
for child processes.
passwd Changes a user's
(requires password.
sudo)
groupadd Creates a new group.
(requires
sudo)
groupdel used to delete a group
(requires from the system.
sudo)
userdel Deletes a user account.
(requires
sudo)
adduser Interactive command to
add a user.
useradd Creates a new user
(requires account.
sudo)
groups used to display the groups
to which a user belongs.

date Prints or sets the system


date and time.
zcat Decompresses and
displays compressed files.
getnet Retrieves entries from
administrative databases.
lslogins Displays information about
known users in the system.
users Lists users currently
logged in.
who Displays information about
users who are currently
logged in.
w Used to display information
about currently logged-in
COMMAND USAGE OPTIONS SYNTAX
users and what they are
doing.
last Shows listing of last logged
in users.
lastb Shows listing of last logged
in bad users.

4. Lab 4 / Lecture 4 + 5 :

COMMAND USAGE OPTIONS SYNTAX


chmod Changes file permissions
chgrp Changes group ownership of files.
chown used to change the ownership of files and directories.
fdisk It allows users to view, create, modify, delete, and
manage disk partitions on hard drives or other storage
devices.
ln used to create links between files.

You might also like