Docsity

Linux Basic Commands Line Part2, Summaries of Network and System Administration

Toggle sidebar
bg1
Linux Review for VC2
Basic Commands Line
Man
mv
Less
Tail
Awk
Cut
Scp
Ssh
Grep
Find
Kill
Netstat
Df
Mount
Tar
Crontab
Touch
I/O redirection
&&, >, >>, <, 2>, &>, |
Ls
Echo
Rm
Cp
Wget
umount
Chmod
Chown
History
mkdir
Commands with example
1. Man: provides offline documentation for all possible option with a command and its usage.
# man cp
2. Mv: is used to move or rename files.
# mv [filename] [new_filename] Rename
# mv [filename] [des_dir] Move
# mv file1.txt backup.txt
# mv backup.txt /home/geeko/downloads
3. Less: allows quickly view file. You can page up and down. Press “ q ” to quit from less windows.
# less install.log
# less -N /etc/passwd
4. Tail: display the last part of file.
# tail –n 100 /var/log/httpd/error_log
5. Useradd: is used for adding/creating user accounts in Linux and other Unix-like system.
# useradd [option] username
# useradd –m geeko (create new user with home directory)
# passwd geeko (assign password to new user)
6. Cut: for cutting out the sections from each line of files and writing the result to standard output.
# cut /etc/passwd -d “:” -f 1 (Display only first filed of the /etc/passwd)
7. Scp: is used to copy file(s) between servers in secure way.
# Scp [src_file_name] [username@des_host:des_folder]
# scp –pv lab.pdf geeko@10.10.0.2:/home/geeko (copy a file to remote host)
# scp –r /mnt/data root@10.10.0.2:/opt/backup (copy all files within /mnt/data folder to remote host)
pf3
pf4
pf5

Partial preview of the text

Download Linux Basic Commands Line Part2 and more Summaries Network and System Administration in PDF only on Docsity!

Linux Review for VC

Basic Commands Line Man mv Less Tail Awk Cut Scp Ssh Grep Find Kill Netstat Df Mount Tar Crontab Touch I/O redirection &&, >, >>, <, 2>, &>, | Ls Echo Rm Cp Wget umount Chmod Chown History mkdir Commands with example

  1. Man : provides offline documentation for all possible option with a command and its usage.

    man cp

  2. Mv : is used to move or rename files.

    mv [filename] [new_filename] Rename

    mv [filename] [des_dir] Move

    mv file1.txt backup.txt

    mv backup.txt /home/geeko/downloads

  3. Less : allows quickly view file. You can page up and down. Press “ q ” to quit from less windows.

    less install.log

    less - N /etc/passwd

  4. Tail : display the last part of file.

    tail – n 100 /var/log/httpd/error_log

  5. Useradd : is used for adding/creating user accounts in Linux and other Unix-like system.

    useradd [option] username

    useradd – m geeko (create new user with home directory)

    passwd geeko (assign password to new user)

  6. Cut : for cutting out the sections from each line of files and writing the result to standard output.

    cut /etc/passwd - d “:” - f 1 (Display only first filed of the /etc/passwd)

  7. Scp : is used to copy file(s) between servers in secure way.

    Scp [src_file_name] [username@des_host:des_folder]

    scp – pv lab.pdf [email protected]:/home/geeko (copy a file to remote host)

    scp – r /mnt/data [email protected]:/opt/backup (copy all files within /mnt/data folder to remote host)

  1. SSH : is a network protocol that enables secure remote connections between two systems.

    ssh 192.168.56.101 ( remote using IP address, by default authenticate with root user)

    ssh srv1.server.com ( remote using domain name)

    ssh [email protected] (remote using IP address and specific username to authenticate)

  2. Cp : This command is used to copy files or group of files or directory

    cp [option] [source] [destination]

    cp file1.txt /mnt/data (copy a file)

    cp file1.txt file2.txt file3.txt /mnt/data (copy group of files)

    cp – r /data /opt/backup (copy directory)

  3. Grep : seach for a given string in a file.

    grep root /etc/passwd

    grep - i network /etc/system/network/eth01.conf

  4. Find : used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.

    find. - name file1.txt

    find /home - iname http.conf

    find /etc – type f – name “*.config”

    find / - mtime 50

  5. Kill : used to terminate the running process (end task) by using process ID.

    ps - ef (list process ID running on system)

    ps – ef | grep tomcat (list specific process ID)

    kill - 9 7580

  6. Netstat : shows the network port in use and their incoming connection.

    netstat – tulpn

  7. Df : display free disk space

    df – h (-h option prints out information in human-readable format)

  8. Mount : is an important command which is used to mount a filesystem that don’t mount itself. You need root permission to mount a device.

    lsblk (first run this command to identify your device, name, and mountpoint)

    mkdir /dev/usb (create new directory as a mountpoint for the device)

    mount /dev/sdb1 /dev/usb

  9. Umount : to umount the file system by specifying the directory path where it has been mounted.

    umount /dev/usb

    umount – f /dev/usb (-f option forcefully unmount a busy device)

  10. Tar : stand for “Tap Archive” is used to create archive and extract the archive files. We also can use tar to create archive files using (tar, tar.gz, tar.bz2) compression.
    • Archive files: are used to collect multiple data files together into a single file for easier portability and storage.
  1. Wget : used to for downloading files from the internet.

    wget http://downloads.sourceforge.net/project/php/0.6.0/php-0.6.0.tbz

  2. Chmod : used to change permission of files, directory, script, etc… There are 3 types of permission: Read (r) = 4 Write (w) = 2 Execute (x) = 1

    chmod 775 /etc/httpd/

    chmod +x /mnt/script/script.sh

  3. Chown : used to change the files ownership. Every file on system belongs to a group of user and an owner.

    chown root:root Desktop/

    chown root:apache /etc/httpd/http.conf

  4. History : when you issue so many commands for testing and debugging, you may forget the useful ones. You can use history to log which commands you used to troubleshoot your application.

    history

  5. Mkdir : used to create directories under linux.

    mkdir directoryname

    mkdir – p test/dir1/dir2 (create directory and sub-directory at the same time)

  6. I/O redirection ( > , >>, 2>, <, <<, | ) The bash shell has three standard streams in I/O redirection: o standard input (stdin) 0. The bash shell takes input from stdin. By default, keyboard is used as input. o standard output (stdout) 1. The bash shell sends output to stdout. Output goes to display screen. o standard error (stderr) 2. The bash shell sends error message to stderr. Error message goes to display screen. Redirect into a File Overwrite: overwrite on existing file contents.  > : standard output # cat /etc/passwd > file.txt  < : standard input # tr ‘a-z’ ‘A-Z’ < sample.txt  2> : standard error # find /tnp – name ‘*.txt’ 2> error.log  &> : redirect to stderr and stdout # sh script.sh &> sample.log Append: do not overwrite on the existing file contents.  >> : standard output # cal 2020 >> calendar.txt  2>> : standard error # grep root /etc/shadow 2 >> error.log

Redirect into a File Pipe ( | ) redirects an output from one command line to be an input of another command line. It execute the first command and redirect the output to second command.

ls – la | head - 5

cat /etc/passwd | grep root | tr ‘a-z’ ‘A-Z

history | tail - 50 | less

Exercises

  1. Create 100 files from Text1 to Text100 by using only one command line
  2. View log file /var/log/http/access.log at real time running
  3. Removes all files in sub-directory /mnt/testing/
  4. Remove all files that start with name “Text”.
  5. Copy file from /etc/network/eth0 to paste on the location that you are working on.
  6. Find files that has been modified at the past 2 months in /etc/.
  7. Find files within /opt/ that have size up to 5MB then delete those file
  8. Find files that start with name “Text”.
  9. Assign permission on main folder /Data to allow user and group have full right and others has only read permission and without effective to permission of sub-directory and files inside.
  10. Copy a file from /mnt/backup.tar.gz to paste in another host that has ip address 10.10.0.2 in location /mnt/backup/.
  11. Compress and archive all documents in /etc/ssh into a single file name start with backup-doc then put in into /mnt/backup.
  12. Extract only one file name network.sh from an archive file script.tar.gz
  13. List contents in directory /opt/ then redirect all result to a file name Output.txt
  14. Search for strings “root” inside a file /etc/passwd
  15. Display how much disk space has been used and free disk space available in the system.
  16. Mount an external hard disk in /run/media/sda1 to attach with folder /mnt/bacula
  17. Display the string “ Hello world! ” to the output screen
  18. Change ownership on a file /etc/http/http.conf that own by user Root and group Root as well.
  19. Using a command line to redirect a sentence “Linux Basic Command Line ” into a file /etc/passwd (Do not overwrite on existing contents).
  20. Create a user name Nano that has home directory at /mnt/nano and add this user to be a member of group Root at the same time.