0% found this document useful (0 votes)
3 views

Linux commands (1)

The document provides a comprehensive guide on basic commands for working with the command line, including displaying strings, managing files and directories, file name substitution, I/O redirection, piping, environment variables, and file permissions. It includes specific command syntax and examples for each category, such as creating files, changing directories, and modifying file permissions. This serves as a reference for users to efficiently navigate and manipulate files and directories in a command-line interface.

Uploaded by

advaidhthebest12
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)
3 views

Linux commands (1)

The document provides a comprehensive guide on basic commands for working with the command line, including displaying strings, managing files and directories, file name substitution, I/O redirection, piping, environment variables, and file permissions. It includes specific command syntax and examples for each category, such as creating files, changing directories, and modifying file permissions. This serves as a reference for users to efficiently navigate and manipulate files and directories in a command-line interface.

Uploaded by

advaidhthebest12
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/ 3

A.

Basics

1. echo SRM ➔ to display the string SRM

2. clear ➔ to clear the screen

3. date ➔ to display the current date and time

4. cal 2003 ➔ to display the calendar for the year 2003

cal 6 2003 ➔ to display the calendar for the June-2003

5. passwd ➔ to change password

b) Working with Files

1. ls ➔ list files in the present working directory

ls –l ➔ list files with detailed information (long list)

ls –a ➔ list all files including the hidden files

2. cat > f1 ➔ to create a file (Press ^d to finish typing)

3. cat f1 ➔ display the content of the file f1

4. wc f1 ➔ list no. of characters, words & lines of a file f1

wc –c f1 ➔ list only no. of characters of file f1

wc –w f1 ➔ list only no. of words of file f1

wc –l f1 ➔ list only no. of lines of file f1

5. cp f1 f2 ➔ copy file f1 into f2

6. mv f1 f2 ➔ rename file f1 as f2

7. rm f1 ➔ remove the file f1

8. head –5 f1 ➔ list first 5 lines of the file f1

tail –5 f1 ➔ list last 5 lines of the file f1

c) Working with Directories

1. mkdir elias ➔ to create the directory elias

2. cd elias ➔ to change the directory as elias

3. rmdir elias ➔ to remove the directory elias

4. pwd ➔ to display the path of the present working directory

5. cd ➔ to go to the home directory


cd .. ➔ to go to the parent directory

cd - ➔ to go to the previous working directory

cd / ➔ to go to the root directory

d) File name substitution

1. ls f? ➔ list files start with ‘f’ and followed by any one character

2. ls *.c ➔ list files with extension ‘c’

3. ls [gpy]et ➔ list files whose first letter is any one of the character g, p

or y and followed by the word et

4. ls [a-d,l-m]ring ➔ list files whose first letter is any one of the character

from a to d and l to m and followed by the word ring.

e) I/O Redirection

1. Input redirection

wc –l < ex1 ➔ To find the number of lines of the file ‘ex1’

2. Output redirection

who > f2 ➔ the output of ‘who’ will be redirected to file f2

3. cat >> f1 ➔ to append more into the file f1

f) Piping

Syntax : Command1 | command2

Output of the command1 is transferred to the command2 as input. Finally

output of the command2 will be displayed on the monitor.

ex. cat f1 | more ➔ list the contents of file f1 screen by screen

head –6 f1 |tail –2 ➔ prints the 5th & 6th lines of the file f1.

g) Environment variables

1. echo $HOME ➔ display the path of the home directory


2. echo $PS1 ➔ display the prompt string $

3. echo $PS2 ➔ display the second prompt string ( > symbol by default )

4. echo $LOGNAME ➔ login name

5. echo $PATH ➔ list of pathname where the OS searches for an executable file

h) File Permission

-- chmod command is used to change the access permission of a file.

Method-1

Syntax : chmod [ugo] [+/-] [ rwxa ] filename

u : user, g : group, o : others

+ : Add permission - : Remove the

permission r : read, w : write, x :

execute, a : all permissions

ex. chmod ug+rw f1

adding ‘read & write’ permissions of file f1 to both user

and group members.

Method-2

Syntax : chmod octnum file1

The 3 digit octal number represents as follows

∑first digit -- file permissions for the user

∑second digit -- file permissions for the group

∑ third digit -- file permissions for others

Each digit is specified as the sum of following

4 – read permission, 2 – write permission, 1 –

execute permission ex. chmod 754 f1

it change the file permission for the file as follows

∑read, write & execute permissions for the user ie; 4+2+1 = 7

∑ read, & execute permissions for the group members ie; 4+0+1 = 5

∑only read permission for others ie; 4+0+0 = 4

You might also like