Basic Commands Final
Basic Commands Final
windows
windows software view
In ubuntu software view
UNIX ARCHITECTURE/COMPONENTS
COMMAND STRUCTURE
• Syntax of command
• Example
• $ ls –l file.txt
• –l is a option
• file.txt is a argument(usually file name)
• The command with its arguments
• The first word in the command syntax is called as command,
• all subsequent words are actually called as arguments.
• Options are also arguments but given a special name because their
list is predetermined.
• There should be at least one space to separate command and
arguments.
OPTIONS:
• With options it can provide information about the size, type of file,
permissions, dates of file creation, change and access
• syntax
• $ ls [options] [argument]
• Complete list of filenames in the current directory arranged in ASCII
collating sequence with one file names in each line
first column
ls –l command displays long list of 7 file
attributes.
• File type and permissions:
The first column shows types and permissions associated with each
file.
• ‘-‘ indicates file is a ordinary file.
• ‘d’ indicates file is a directory.
• b or c indicates device file
ls –l command displays long list of 7 file
attributes.
• File type and permissions:
9 characters in first column shows permission.
Second column
ls –l command displays long list of 7 file attributes.
• Third column
• Ownership:
• The third column shows owner of the file, owner is the person who
has created the file. Owner can create, modify or remove files in a
directory
ls –l command displays long list of 7 file
attributes.
Third column
ls –l command displays long list of 7 file attributes.
• Fourth column
• Group Ownership:
• When opening a user account, the system administrator assigns the
users to some group.
• The fourth column represents group owner of the file.
ls –l command displays long list of 7 file
attributes.
Fourth
column
ls –l command displays long list of 7 file attributes.
• Fifth column
• File size:
• The fifth column shows the size of the files in bytes. The amount of
data it contains.
• It is the character count of the file and not a measure of disk space that
it occupies.
• The space occupied by a file on the disk is usually larger than this
because files are written to a disk blocks of 1024 bytes.
ls –l command displays long list of 7 file
attributes.
Fifth column
Note : size of file 4byte for 4charcter
sixth column
• Modification time: The sixth column shows the date and time when
the file or directory was last modified.
six column
Seventh column
• Name: The seventh column shows the name of the file or directory.
Seventh
column
Note : syntax of command
• $COMMAND [OPTIONS] [ARGUMENTS]
ls -d
The ls -d command, without additional arguments, is used to list directories
themselves, rather than their contents.
ls –ld
• ls -ld command is used in Unix-like operating systems (such as Linux) to display information about a
directory.
d means directory
ls-lh
• The ls -lh command in Linux/Unix is used to list files and directories in the current
directory with human-readable file sizes
• -l option lists files in long format (which includes file permissions, number of links,
owner, group, file size, and modification date)
• the -h option makes the file sizes human-readable (i.e., showing sizes in KB, MB,
GB instead of just bytes).
Syntax :
ls -lh [directory]
• -l: Long listing format.
• -h: Human-readable sizes.
• [directory]: Optional. Specify the directory you want to list. If omitted, it lists the
contents of the current directory.
Example
•total 104K:This indicates the total size of the files listed, which is 104 kilobytes. This is the sum of all file sizes in
the current directory.
•1.File name: 'unix-Self audit961.docx' (with spaces, enclosed in quotes).
•Size: 101K (kilobytes).
•Last modified: January 20, 2024.
explanation
• total 104K:This indicates the total size of the files listed, which is 104
kilobytes. This is the sum of all file sizes in the current directory.
• Syntax :
• ls -R [directory]
• -R: Lists all files and directories recursively, showing the contents of each
subdirectory.
• [directory]: Optional. Specify the directory you want to list. If omitted, it lists the
contents of the current directory and all subdirectories.
Example
• Syntax: ls -a [directory]
• -a: Shows all files, including hidden ones (files starting with .)
• [directory]: Optional. Specify the directory to list. If omitted, the command will
list the contents of the current directory.
Files and folder in unix1
Example :
Listing of file
U can check the content of new file and also new file created in
directory
2.1 : to overwrite the contents of an existing file
The cat command is often used to concatenate and display the content
of files. If you want to overwrite the contents of an existing file using
the cat command, you can use the following
syntax:
2. 2 : create a file and adding contents
Example of 2.2 :
Press Enter
Cltrl + d
2.3 : append the text ( by using >> )
Example : Appending existing file
• used to display or set the current date and time on Unix-like operating
systems
Various options of date command
+%FORMAT: Display the date and time using a specific format.
The FORMAT argument specifies the format of the output.
For example
%Y represents the year,
%m represents the month,
%d represents the day,
%H represents the hour,
%M represents the minute, and
%S represents the second
Example
• %Y represents the year
5.calendar
Example :
8. echo command
• Display text or output to the screen. It's often used for printing
messages, variables, or other information.
9.Whoami command
The whoami command is used to display the username of the current user in a Unix
Example :
9.Cd command : change the current working directory
Example :
Move to Parent Directory
• This command is used to move up one level in the directory structure
cd use to move to sub directory
Syntax
Listing of files Listing of all files
Listing of files
10. mkdir
• mkdir (make directory) command in Unix/Linux and other command-
line interfaces is used to create new directories.
• Syntax:
• mkdir [options] directory_name
• directory_name: The name of the directory (or directories) you want to
create. You can specify an absolute or relative path.
• Options:-p: Creates parent directories as needed.
10.
The mkdir command is used to create a new directory (folder) in a file system.
The name "mkdir" stands for "make directory.“
Listing of files
Creating directory
• Syntax :
• rmdir my_directory
• This command removes the directory my_directory, but only if it is empty.
Example :
The rmdir command is used to remove (delete) empty directories in a file system.
Listing of files
Remove directory
Listing of files
12.mv command
The mv command in Unix-like operating systems is used to move or rename files and directories.
Here are some examples of how to use the mv command:
Listing of files
Syntax :
• 1.option : -n
• Numeric sort
Example
2. Sort a file in reverse order:
Syntax
2. Sort a file in reverse order:
Example
Content of file
• Syntax :
• alias shortcut_name='command_to_run'
17.
18: bash command in windows
1.The first line of a script, often starts with #!/bin/bash, indicating the path to the shell
interpreter.
2.Comments: Lines starting with # are comments and are ignored by the shell. You
can use comments to explain what the script does.
Press i : enter into append mode
To save press ESC and shift : (colon) wq
To run the command
• To make script executable we use chmod
• $ chmod +x p1.txt
• Run command
• sh filename.txt or sh filename
1.File contents
Output
20.find command
• It allows users to search for files based on various criteria such as file
name, size, modification time, and more.
1. Find files by name:
• $ find ./ -name "p1.txt"
Syntax
type command : 1. Check if a command is an
external command:
Here's an example:
$command1 ; command2
Output of Command 1
Output of Command 2
• In Unix, the exit status is a numeric value that represents the result of a command.
• A value of 0 : usually indicates success
• while non-zero values : typically indicate an error or failure.
Display contents , command successful
x =5 and y=7
x not equal y ,so
result is false
-lt : less than equal
x =5 and y=7
x less than y so result True
We will apply test command only for integer
Output: 8
Arithmetic Expressions : Division
Output: 5
24.Set
The set command can be used to set or modify positional parameters.
Syntax
Shift [ n ]
• Here, n is an optional parameter that specifies the number of positions to shift. If n is not
provided, it defaults to 1, meaning the positional parameters are shifted left by one position.
Step 1: Set value to positional parameters
$1 $2 $3 $4 $5 $6 $7
11 12 13 14 15 16 17
12 13 14 15 16 17
$1 $2 $3 $4 $5 $6 $7
Step 1 : set positional parameters using set command
$1 $2 $6 $7
$3 $4 $5
We can display positional parameter using echo statement like $1 $2 $3 for first second and third positional parameters
Output
Step 2 : shift this positional parameters to left
• After setting the positional parameters we will shift those parameters by using shift commands
• Example
• 1. Set the positional parameters
Syntax :
$grep [options] pattern filename(s)
Example .Basic search
1
To search for the term “college " in a file named p2
So, the command searches the file p2 for any occurrences of the
word "college" and outputs the lines that contain it. Since "college"
is the only matching line in this case, it is printed as the result.
Unix
tr command
awk
• Used for text processing and extracting specific fields in a file.
• Syntax:
• Syntax :
• paste [options] file1 file2
• file1 and file2: Input files whose lines will be combined horizontally.
• Options:-d: Specify a custom delimiter instead of the default tab.
• -s: Merge all lines from each file serially.
Example 1 :
The paste command combines the lines of two files
$ cat p3 horizontally. By default, the fields are separated by a tab
character.
1
2
3
Apply paste command
$ paste p2 p3
Output : A 1 Execution:Combines corresponding lines from p2 and p3 side
B 2 by side.
Uses a tab character as the default separator.
C 3
Example 2 : -d option
$ cat p3 The -d option in the paste command specifies a custom
delimiter. In this case, the delimiter is a hyphen (-).
1
2
3
Apply paste command – d
$ paste -d "-" p2 p3
• Output : A-1
• B-2 Execution:Combines lines from p2 and p3.Replaces the default
tab character with a hyphen.
• C-3
Example 2 : -d option
The -s option merges all lines from each file serially instead of
$ cat p3 line by line.
1
2
3
Apply paste command – d
$ paste -s p2 p3 Execution:Reads all lines from each file.Combines all lines from
p2 into one line and does the same for p3.Uses the default tab
• Output : A B C
character to separate entries.
• 1 2 3
top Command
• top command displays real-time system information, such as
processes, CPU usage, memory usage, and more. It's a powerful tool
for monitoring system performance.
• Syntax:
• top [options]
Key Features
• Provides a dynamic, real-time view of system performance.
• Displays processes and their resource consumption.
• Updates automatically at regular intervals (default: every 3 seconds).
• Fields in the top Output:
• Tasks: Total number of processes and their states (running, sleeping, stopped, or zombie).
• CPU Usage: Percentage of CPU time used by user, system, idle, etc.
• Memory Usage: Total and used physical memory (RAM).
• Swap Usage: Total and used swap memory.
• Process List: PID: Process ID.USER: User running the process.
• %CPU: Percentage of CPU time consumed.
• %MEM: Percentage of memory used.
• COMMAND: The command or program running.
env
• Shows the current environment variables or runs a command with a
modified environment.
• Syntax
• env [options] [command]
Example :
• Display all environment variables:
Jobs
• Syntax :
• jobs [options]
• Example:
List all jobs:
chmod Command in Linux
• Syntax:
• chmod [permissions] file
• Explanation:
• 7: Full permissions (read, write, execute) for the owner.
• 0: No permissions for the group.
• 0: No permissions for others.
Example 2.
• Grant read and execute permissions to everyone:
• Explanation:
7: Full permissions for the owner.
5: Read and execute for the group.
5: Read and execute for others.
• Symbolic Format:
• You can use symbols to modify specific permissions:
• + ( Add a permission).
• - (Remove a permission.)
• = (Set exact permissions.)
• Example:
• Grant execute permission to the owner:
Example of Symbolic Format: