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

THE FIRST STEP TO LINUX PART 1 - THE BASIC COMMANDS

Uploaded by

dave hill
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)
11 views

THE FIRST STEP TO LINUX PART 1 - THE BASIC COMMANDS

Uploaded by

dave hill
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/ 43

The first step to

Linux

Part 1:
The basic
commands
Olivoy
Edition : 1.0
Copyright© 2017
Olivoy
All rights reserved
Table of contents

Operating System Control Commands


To turn off the system immediately
To turn off the system after 10 min
To restart
To restart after 10 min
To schedule system shutdown
Commands for compressing and
decompressing files
To create a compress file with the tar
extension that has the name file.tar
To unpack the file
To create a compressed file by the Gzip
program
To decompress the file created by Gzip
To create a file compressed by the
Bzip2 program
To decompress the file created by Gzip
File Commands
View the contents of a current directory
Navigating from one directory to
another.
Creating a copy of a file.
Move a file
To delete a file or directory
Creating a directory
Creating a file
Editing a file
Change the owner of a file or directory.
Change the rights of a file or directory.
To search for files.
Disk space
Operating System
Control Commands
To turn off the system
immediately
shutdown -h now

or

halt
Note: this command requests the
rights of Root (sudo halt)
To turn off the system
after 10 min

shutdown -h +10
Note 1: This command requests Root
rights (sudo shutdown -h +10)
Note 2: To cancel the system
shutdown before 10 min use the
following command:
shutdown -c
To restart

shutdown -r now
reboot
To restart after 10 min

shutdown -r +10
Note: To cancel the restart of the
system before 10 min use the
following command:
shutdown –c
To schedule system
shutdown

shutdown -h 21:00
Note 1: This command requests
Root's rights
Note 2: To cancel the scheduled
shutdown use the following
command:
shutdown -c
Commands for
compressing and
decompressing files
To create a compress file
with the tar extension
that has the name file.tar
tar cf file.tar files
tar cf file.tar file1.c file2.cpp
To unpack the file

tar xf file.tar
To create a compressed
file by the Gzip program

tar czf file.tar.gz files


tar czf file.tar.gz file1.c file2.cpp
To decompress the file
created by Gzip

tar xzf file.tar.gz


To create a file
compressed by the Bzip2
program

tar cjf file.tar.bz2 files


tar cjf file.tar.bz2 file1.c file2.cpp
To decompress the file
created by Gzip

tar xjf file.tar.bz2


File Commands
View the contents of a
current directory

View detailed information ls -l

Show hidden files ls -a

Display file size readable ls -h

Inverted Sorting ls -r

Sort files by date from newest


ls -t
to oldest
Sort by size descending ls -S

Show all files including


ls -la
hidden files

View file information, with


ls -
readable sizes all ordered
lhS
from largest to smallest
Navigating from one
directory to another.

Lets get to the root of


cd /
the disc.

Go directly to the user's


cd ~ ou cd
directory.

Go to the /var/www cd
directory. /var/www/

Go back to the parent


directory from where cd ..
you are
Return the absolute path
pwd
of the current directory.
Creating a copy of a file.

Copy the
archive.tar cp
file to the Documents/archive.tar
Desktop Desktop/
directory

Copy entire cp -r Documents/


directories Desktop/
Move a file

To do this, use the mv command. This


command also allows you to rename
your files.

Move the
archive.tar mv
file to the Documents/archive.tar
Desktop Desktop/
directory

Rename the
archive.tar mv archive.tar
file to archive001.tar
archive001.tar
To delete a file or
directory

Delete all files with


rm *.tar
tar extension

Delete both
rm archive.tar
archive.tar and
Doc.txt
Doc.txt files

Delete the
rm -rf
Documents directory
Documents/.
and all its contents
Creating a directory
To create a directory simply use the
mkdir command. It will allow you to
create a directory at the location where
you are or the location specified in the
command's argument.

mkdir rep1
Creating a file

touch file.txt
Note: If the file name contains a space
used in quotation marks
touch "file part1.txt"
Editing a file
nano file.txt
The ^ symbol means Ctrl (the Control
key on your keyboard). So, to quit Nano,
just type Ctrl + X.
Here are the most important shortcuts:
Ctrl + G: display help;
Ctrl + K: cut the line of text (and put
it in the clipboard);
Ctrl + U: paste the line of text you
just cut;
Ctrl + C: display where your cursor
is positioned (line number ...);
Ctrl + W: search in the file;
Ctrl + O: save the file (write);
Ctrl + X: Exit Nano.
Change the owner of a file
or directory.
Assign the user user1 and the
administrator group to the archive.tar
file

chown user01:administrator
archive.tar
Change the rights of a file
or directory.
To execute this command you must be the
owner of the file or be the root.
For a file: chmod [u g o a] [+ - =] [r w
x] file_name
For the contents of a directory: chmod -
R [u g o a] [+ - =] [r w x]
directory_name
u: owner (user)
g: group
o: others
a: all

r (4): Read permission


w (2): write permission
x (1): execution authority
Example

Add write permissions to chmod


u+w
the owner (user, write) file.txt

Add playback rights to chmod


the group of the file g+r
(group, read) file.txt

Delete execution rights to chmod o-


other users (other,
execution) x file.txt

chmod
Add read and write a+rw
permissions to all (all)
file.txt
Add Read and Execute
rights to everything that chmod -R
contains the directory a+rx rep1
rep1

Rights representation correspondence


Right Alphanumeric Octal
value value
no right --- 0
Execution --x 1
only
Write only -w- 2
Writing and -wx 3
executing
Read only r-- 4
Reading and r-x 5
execution
reading and rw- 6
writing
All rights rwx 7
(reading,
writing and
executing)

chmod 764 archive.tar


Note: All rights for the owner (7xx),
reading and writing for the group
(x6x) and reading only for the others
(xx4).
To search for files.

Some options:
-name: Finding a file by name
-iname: Same as -name but case
insensitive
-type: Finding a file of a certain type
-atime: Search by date of last access
-mtime: Search by Last Modified
Date
-user: Search for files belonging to
the given user
-group: Search for files belonging to
the given group
-size: Search relative to a file size.
-exec: Execute the command given to
the found files.
-a: AND operator
-o: OR operator
! Or -not: Operator NOT

Search for a file


beginning with find myfile*
"myfile"

Search for a file


containing "myfile" find
and having for *myfile*.txt
extention ".txt"

Searches for a txt file find -name


that begins with "d" "d*.txt"
File that begins with
find -iname
"d" or "D" not case-
"d*.txt"
sensitive

Show all /usr find /usr -


directories type d

find /usr -
Show all files in /usr
type f
Disk space

To know the disk space


du -sh
used of the two
rep1 rep2
directories (disk usage)

Display the used disk


du -hc --
space of the files and
max-
directories contained in
depth=1
a directory

Display free disk space df -h

You might also like