Linux Basic Commands

  • Uploaded by: Lalit
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Linux Basic Commands as PDF for free.

More details

  • Words: 2,097
  • Pages: 16
Linux Basic Commands Although GUI file manages in Linux graphical environment easy to use, you can use them only if you are working in GUI desktop. If due to any reason you don’t have GUI, you have to rely on Linux commands to work with files & directories. Of course you can always use Linux commands even in graphical environment, by opening a new terminal window.

1. Displaying files & directories $ ls

(displays files & directories)

$ ls –a

(displays hidden files too)

$ ls –l

(displays about links too)

2. Creating text file $ cat > <enter> …………….Type the matter here……………. Press ‘ctrl’ + ‘D’ keys to save the file

3. Adding more data to existing Text file $ cat >> <existing filename> <enter>

4. Displaying contents of file $ cat <enter> $ head <enter> $ head –n 5 <enter>

(displays top 5 lines of the file)

$ tail <enter> $ tail –n 5 <enter>

(displays bottom 5 lines of the file)

5. Changing directory $ cd

(To go to mother directory of current directory)

$ cd \

(To go to root directory)

$ cd

(Togo to specified directory)

6. Making directory $ mkdir <enter> 7. Deleting files $ rm

8. Removing directories $ rmdir

(to remove an empty directory)

$ rm –r

(to remove directories in recursive manner)

9. To copy files from one location to another $ cp <source file name> <destination directory name> <enter> $ cp –a <source file name> <destination directory name> <enter>

10. Moving file from one location to another location / renaming files $mv <destination directory name> <enter> $ mv <destination directory name> <enter>

11. Creating empty file $ touch < enter>

12.Displaying System Date & Time $ date <enter>

13. Displaying current working directory $ pwd <enter>

14.To find given string in file $ grep string filename <enter>

User Administration commands 1. Creating user $ useradd <username> <enter> $ adduser <username> <enter>

2. Setting password for created user $ passwd <username> <enter>

3. Changing password $ passwd <username> <enter>

4. Rename a user account name $ usermod –l

5. Modifying Existing users

a) Managing password aging (i)

To lock (disable) the user name # passwd -l <username>

(ii)

To unlock (enable) th user account # passwd –u <username>

(iii)

To set password to blank # passwd –d <username>

(iv)

Show status of user’s password # passwd –S <username>

(v)

Specifies the no. of days a user must retain same password # chage –m 0 username

(vi)

Specifies the max no. of days user can use same password # chage –M 30 username

(vii)

Sets the expiration date for the users password # chage –E 2005-07-1 username

(viii) Sets the no. of days before password expiration user receives warning # chage –W 7

6. Adding groups # groupadd <enter>

7. Adding user to group # usermod –g <username> <enter> (for making user member of primary group) # usermod –G <username> <enter> (for making user member of secondary group)

8. Deleting user # userdel <username> <enter> # userdel –r <username>

9. Deleting group # groupdel <enter>

10.Rename a group # groupmod –n

11. Displaying user information # who <enter> #whoami <enter>

12.Switching to another user # su <enter>

File Access Permissions Commands Every file has both user & group ownership. A newly created file will be owned by the user who creates it. 1) Default file permissions $ umask <enter> , if you want to default permissions you can use the command with new value of the mask eg $ umask 0011 <enter> , this will set the default permissions for the directory and for files 666. 2) Permissions r–4 w–2 x–1 They come out in 9 characters eg r-xr-xr--. First 3 characters are for owner next 3 for group & last 3 for others. This implies permission 765 means as 421 i.e read, write, execute for owner 42- i.e read, write for group 4-1 i.e read, execute permissions for others.

3) Set sticky bit for a directory (With sticky bit set on a directory only the owner of the directory can delete it even if others have write permissions on the directory) # chmod 1777 <enter> 4) Change ownership of the file (user/group) # chown <username> (Changes the ower of file) # chgrp (Changes the group associated with file or directory)

File System Attribute 1. Display current attributes $ lsattr <enter> 2. Set attributes $chattr +/- attributes Attributes: A- Time record is not modified upon access or modification. a- File can only be opened in append mode for writing. i- It can’t be deleted or modified.

Linking Files 1. Set hard link to the file $ ln (Hard link indicates a single file with multiple names in same directory or different directories, all the file names have same inodes)

2. Set softlink to file $ ln –s (Soft link is only a pointer to actual file , it is like a shortcut to a fiel , all soft links have different inode numbers).

3. Displaying linking files $ ls –l <enter> (Note : The file having first character field as ‘l’ are linking files (indicating softlinks)

Linux Processes Linux Kernel assigns a unique PID for each process. Process ID(PID) numbers are between 1 and 32768. PID 1 is reserved for ‘init’ process.

1. Monitoring Process Status $ ps <enter> $ top <enter> (process using the CPU and Memory status in text mode) $ gtop <enter> (process using the CPU & memory status in graphics mode) 2. Displaying Current User Status $ id <enter>

3. Sending Signal To Process $ kill <enter>

4. Terminating Process $ Press ‘ctrl’ + ’c’

5. Using Different Virtual Console a) Press ‘ctrl’ + ‘alt’ + F1 to F7 (F7 for X Window) b) Press ‘Shift’ + Pg Up or Pg Dn keys to move into open terminals

6. Checking Free Space In HDD $ du <enter>

(disk usage)

$ du –h <enter>

(disk usage in human readable form)

$ df <enter> $ df –h <enter>

Mounting / Unmounting Devices 1. Floppy Disk Drive $ mount /mnt/floppy

(To enable access to floppy)

$ mount –t ext3 /dev/fd0 /mnt/floppy $ umount /mnt /floppy

(To disable access to floppy)

2. CD-ROM Drive $ mount –t iso9660 /dev/cdrom /mnt/cdrom $ mount /mnt/cdrom

(To enable access to CD-ROM)

$ umount /mnt/cdrom

(To disable access to CD-OM)

3. Creating An Installation Boot Disk From DOS a) Go to the Linux CD DOSUTILS Directory b) Run the rewrite program in this directory D:\dosutils>rewrite c) Enter the disk image source file D:\image\boot.img. d) When prompted , enter target diskette drive : a:. e) Insert a formatted diskette into drive A: & press ENTER.

4. Creating BOOT Disks from Linux # mkbootdisk kernel_version_number <enter> kernel_version_number can be knowm by typing # uname –r

Locating Files 1. Finding Files $ find / -name filename –print <enter> $ whereis

2. Finding String In Any File $ ps ax | grep stringname <enter>

Printing 1. Printing Files $ lpr <enter> $ lpr –P printername -# No. of copies filename <enter>

2. Printer Queue Status $ lpq <enter>

3. To Remove Print Job From Queue $ lprm job number <enter>

4. Printer Administration $ printtool

Basic Network Commands 1. Checking Connectivity With Remote System (Network Packets Lose & Latency Measurement Tool) $ ping IP address <enter> $ ping Hostname <enter>

2. Query To Domain Name Server $ nslookup IP address <enter> $ nslookup servername <enter> $ host servername <enter>

3. Remote Login $ telnet IP address <enter>

4. Multipurpose Network Information Tool $ netstat

5. Secure Shell (ssh) # ssh user1@server2 Then Type “yes” # scp filename user1@server2: /etc/services # scp /etc/named.conf [email protected]:/etc # scp –r localhost:remote directory would copy the contents of localdir into remote –dir # sftp -c user1@server2 ( log into server2 with username of user2 & present a password prompt & an interactive ftp-type session.

Red hat Package Manager (RPM) 1. Query about installed RPM $ rpm –qa <enter>

2. Installing RPM $ rpm –ivh package name -version number –architecture.rpm <enter> ( eg

$ rpm –ivh samba -2.0.1.10 –i386.rpm <enter>)

3. Uninstalling RPM $ rpm –e package name <enter> (eg

$ rpm –e samba <enter> )

4. Upgrading RPM $ rpm –Uvh package name –version number –architecture.rpm <enter> ( eg

$ rpm -Uvh samba -2.0.1.10 –i386.rpm <enter> )

5. Displaying RPM Details # rpm –qi samba <enter>

Visual Editor ( VI Editor) 1. To create file using vi editor. 2. Editing file with vi editor. Go to command mode by pressing

escape if you are currently in insert mode. Following are some of the useful commands of vi editor :0 – moves the cursor to the beginning of the current line $ - moves the cursor to the end of the current line w – moves the cursor to the beginning of the next word

b – moves the cursor to beginning of previous word H – moves the cursor to the upper left hand corner of screen L – moves the cursor to the lower left hand corner of screen x – deletes the current character directly under the cursor X – deletes the current character directly before the cursor Ndw – deletes next N words where N is any integer Nj – moves down N lines :q – quits without saving changes :wq – write & quit zz – same as :wq G – Go to the last line NG – Go to Nth line u – undo the previous change made Ndd – deletes N number of lines from current position Nyy – yankes ( copies & puts into buffer ) N lines from the current position p – prints( pastes) the yanked lines starting from the current character position /string – searches for the particular string in the file and highlights it :se nu – set line number in the text

Backup To Tape Drive Red Hat Linux Supports Many Tape Devices i)

IDE tape devices /dev/hd0,hd1

ii)

SCSI taper devices ( i.e. , DDS, DAT) /dev/st0 , /dev/st1

iii)

Floppy Tape Devices /dev/rft0 , /dev/rft1 ..

1. To Backup File $ tar cf /dev/st0 filename <enter>

2. To use gzip compression $ tar zcf /dev/st0 filename <enter>

3. To extract from a compressed archive file $ tar zcf /dev/st0 <enter>

System Log Files 1. Monitoring log files with help of detect i)

Equipment problems such as a disk crashes

ii)

User problem such as repeated login failures

iii)

Security breaches from outside the system

2. Log file monitor include i)

#/varmessages ( Logs most system messages)

ii)

#/var/log/secure (authentication messages,xinetd services)

iii)

#/var/log/xferlog (ftp transactions)

iv)

#/var/log/maillog (mail transactions)

3. The information contained in /var/log/messages include i)

Date & Time the messages were written

ii)

Name of the utility the messages were written

iii)

Action that occurred

iv)

Executing programs hostname The exact information in a log file depends on the application. Many applications create their own log files which may also need to be monitored.

DNS SERVER 1. To check whether dns is installed or not $ rpm –qa named

2. Install dns services $ rpm –ivh named*

3. Configure DNS master file & Reverse files a) $/etc/named.conf b) $/var/named/forwardfile c) $/var/named/reversefile d) $/etc/resolv.conf

4. Start DNS services $ service named start

5. To check whether DNS server resolving your IP to Nameserver and Nameserver to IP $ dig $ nslookup IP address

Samba Server 1. To check whether samba is installed or not $ rpm –qa samba*

2. Install Samba $ rpm –ivh samba*

3. Add new user to your system and specify passwd # adduser newuser

4. Create a smbpasswd file and then add a password for new user # touch /etc/samba/smbpasswd # smbpasswd -a newuser

5. Restart samba services # service smb restart 6. A working Samba server accessible to user with smbclient # smbclient //servername/share –U username

7. Mounting SMB file # smbmount //servername/share mountpoint –o username=smbuser 8. Samba mounts can be performed automatically upon system

boot by placing an entry in /etc/fstab file //server1/public /mnt/smb smbfs defaults , username=nobody 0 0

Proxy Server 1.

Check whether squid proxy is installed or not

# rpm –qa squid if installed you will get message : squid 2.4 STABLE7-4

2. Install Proxy if not installed $ rpm –ivh squid*

3. Configure squid.conf 4. Restart squid server # service squid restart

Related Documents

Linux Basic Commands
June 2020 16
Linux Basic Commands
June 2020 11
Linux Basic Commands
June 2020 10
Basic Linux Commands
June 2020 18
Linux Basic Commands
June 2020 23
Basic Linux Commands
May 2020 19

More Documents from "Adarsh"

Sap Modules.docx
November 2019 27
Moon Mission
April 2020 14
Cm Report Lalit.docx
November 2019 24
Title Page Cm Lalit.docx
November 2019 16