Basic Linux Commands

Some basic useful linux commands

ยท

4 min read

Hello, techies!

Welcome to my article on Linux basic commands. In this article, I will give you some basic bash commands that will help you to interact with Linux efficiently and easily manage bash operations. Here are the few commands that are most frequently used in Linux:

1. PWD (Present Working Directory)

pwd commands tell the location of the current working directory image.png

2. CD (Change Directory)

cd command is used to change the directory

SyntaxDescription
cd directory_pathchange to directory path
cd ..move back to parent directory
cd ~switch to user home directory
cd -change to previous path
cd .current location

image.png

3. Date Command

date command in Linux is very important, here is some basic usage of the date command.

SyntaxDescription
date -u universal date and time
date +"%T" display only time
date +"%B" display month name full
date +"%d" current date
date +"%D" half date fomat
date +"%F" full date format
date +"%m%d%H%M%Y%S"to see the new format

image.png

For more date options refer to doc

4. Calendar Command

cal is a calendar command in Linux to view the calendar of a specific year or month. Here are a few usages in Linux.

SyntaxDescription
cal current month/year calendar
cal -y 2020 show all month of that year
cal 03 2020shows the month of specified number year

image.png image.png image.png

5. Time Command

time is a command in Linux to view resource usage to file timestamp

SyntaxDescription
timecheck the execution time
time [options]option specific output

image.png

For time options refer to doc

6. Directory Commands

The most used directory commands are mkdir and rmdir

SyntaxDescription
mkdir directory_nameto create a directory
mkdir -pspecify full parent directory path creation
mkdir -vprint a message for each created directory
mkdir -Zselinux context
mkdir -mset the mode on directory

image.png

Sources doc mkdir

SyntaxDescription
rmdirto remove a empty directory

image.png

Sources doc rmdir

7. List Command

ls is the most used command in Linux with multiple options, here are a few which are used most occasionally

SyntaxDescription
ls -l long listing
ls -a to list hidden files and folder
ls -i to list inode of files or folder
ls -r to list in reverse order (ascending order)
ls -t to list according to time
ls -h to list in human-readable format
ls -lSto list in desc order of file size
ls -dto list directory
ls -hlto list in human-readable format

image.png image.png image.png

Note: We can use the combination of options together also

image.png

Sources doc

8. Move Command

mv is the command in Linux used to rename a file/folder

mv [options] old_name new_name

image.png

For options refer to doc

9. Touch Command

touch is the command in Linux used to create an empty file.

touch [options] file_name

image.png

For options refer to doc

10. Vi Command

vi is the inbuilt file editor command in Linux with multiple options, at the basic level just know the syntax and for options refer to doc

vi [options] file_name

image.png image.png

Option used for editing, deleting, saving files within vi editor

  • Press esc + : i = to enter in insert mode image.png
  • Press esc + : q = to quit file without modifying image.png
  • Press esc + : x = to save file and exit image.png
  • Press esc + : w = save the changes made in file image.png
  • Press esc + : q! = exit file discarding the changes made in file
    image.png
  • Press esc + : yy = to yank line (copy line)
  • Press esc + : dd = to delete line

Thank you for reading!

Source link

ย