THE FIRST STEP TO LINUX PART 1 - THE BASIC COMMANDS
THE FIRST STEP TO LINUX PART 1 - THE BASIC COMMANDS
Linux
Part 1:
The basic
commands
Olivoy
Edition : 1.0
Copyright© 2017
Olivoy
All rights reserved
Table of contents
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
Inverted Sorting ls -r
Go to the /var/www cd
directory. /var/www/
Copy the
archive.tar cp
file to the Documents/archive.tar
Desktop Desktop/
directory
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 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
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
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
find /usr -
Show all files in /usr
type f
Disk space