Vous êtes sur la page 1sur 8

1) To explain what the shell commands perform like cd with arguments, pwd, cp, move, rm with

arguments, mkdir with arguments, chmod, ls, etc.

1- cd with arguments
cd changes the current directory of the shell. This current directory will be used by other programs
launched from the shell.
Examples
Change to 'foobar' directory:
$ cd foobar
Change to your home directory, cd command used without an option will drop you back into your
home directory.
$ cd
~ (tilde) stores the path to your home directory, this command has same effect as the previous one.
$ cd ~
Change to parent directory:
$ cd ..
Change to the previous directory:
$ cd -

2- pwd
pwd (for Print Working Directory) shows the current directory that you are in.
Examples
$ pwd
/home/username
You can change the directory, you can also
$ cd /usr
$ pwd
/usr

3- cp
cp copies a file
Most used options are:
-r copies directories (recursively)
-p preserves permissions, ownership, and timestamps
-i prompt before overwrite
-v verbose, show filenames as they are being copied
Examples
Makes a copy of file 'debian' and call it 'Debian' (assuming 'Debian' is
not already a directory)
$ cp -i debian Debian
Makes a copy of file 'debian' and put it at /tmp/debian
$ cp -i debian /tmp/debian
Same as the previous command (the filename defaults to be the same).
$ cp -i debian /tmp
Makes a copy of directory 'mydir' (and all its contents) and put it at
/tmp/mydir
$ cp -ir mydir/ /tmp
Copy multiple files to directory /tmp
$ cp -i foo bar baz /tmp

4- mv
mv move and/or rename files
Examples

Rename file 'unix' to 'Unix' (assuming "Unix" is not a directory)


$ mv -i unix Unix
Move file Unix from your home directory to /tmp.
$ mv -i ~/Unix /tmp/Unix
Same as the previous command (the filename defaults to be the same).
$ mv -i ~/Unix /tmp
Move file Unix from your home directory to /tmp, and rename it to 'unix'.
$ mv -i ~/Unix /tmp/unix
Move multiple files to directory /tmp
$ mv -i foo bar baz /tmp

5- rm with arguments
rm deletes a file from the filesystem, like the "del" command in DOS.
The GNU long options (like --directory) are available on Linux, but not most other systems.
Some useful options are:
-d, --directory unlink FILE, even if it is an empty directory (some systems let superuser unlink
non-empty directories too)
-f, --force ignore nonexistent files, never prompt
-i, --interactive prompt before any removal
-P (*BSD only) overwrite file before deletion
-r, -R, --recursive remove the contents of directories recursively (the force option must often
be used to successfully run rm recursively)
-v, --verbose (GNU only) explain what is being done
--help (GNU only) display help and exit
--version (GNU only) output version information and exit

6- mkdir with arguments


mkdir is a utility for creating a directory.
Examples
$ mkdir newdirectoryname
The -p option also makes parent-directories as needed. Instead of:
$ mkdir foo
$ cd foo
$ mkdir bar
you can just do:
$ mkdir -p foo/bar

7- chmod
chmod changes permissions of files. One must be familiar with Unix file permissions to understand
this command. There are three permissions: read ("r"), write ("w"), and execute ("x"). There are three
sets of permissions: for the owning user of the file ("u"), for the group of the file ("g"), and for other
users ("o").
-R
recursively change or set permissions on an entire directory tree
Examples:
$ chmod +x configure
$ ./configure
$ chmod u+x configure
$ chmod go-x configure
$ chmod go-rwx ~/mail ~/private
# chown :wsrc /usr/local/src
# chmod g+rwx /usr/local/src
2) To create a user with/without a home directory letting it create the default home directory of
the user or specifying another one.

To create a use with home directory (by default /home/jane)


# useradd jane
# passwd jane
# less /etc/passwd
q
# su jane

o create a user without home directory (-m)


# useradd -M jane
# ls –l /home/jane

To create a user with home directory (-m)


# useradd jane1 –m –s /bin/bash
# passwd jane1
# less /etc/passwd
q
# su jane1

Create a User with Different Home Directory


# useradd –d /data/projects jane

To create the home directory in a later stage


# sudo mkdir /home/jane
# sudo chown jane /home/jane
# sudo chgrp jane /home/jane

To create a user with Account Expiry Date


# useradd –e 2019-03-01 jane2
# chage –l jane2 (tregon kur ben expire passwordi)
# tail –1 /etc/passwd ( per te pare line e fundit)

To create a user with password expiration date, (45 dite)


# useradd -e 2019-03-01 -f 45 jane

account with the rights of administrator.


# useradd –G admins jane
Creating user group and including the new user account into that group, deleting a user and login to the
new user created after unlocking it, also the command to lock the root user after you have added the
user to the pool of superuser.

# sudo addgroup dekra


# sudo adduser jane dekra (ose) # sudo usermod –aG dekra jane
# userdel jane
# userdel –r jane (delete the user and its home directory)

also the command to lock the root user after you have added the user to the pool of superuser.
# sudo adduser jane sudo (ose) # usermod -aG sudo jane
# sudo passwd –l root (to lock the root user)
# sudo passwd –lock jane (to lock the user)

3) How do we create a partition in Linux with gparted and fdisk, print screen on how we manage
through the commands and by using the graphic with gparted and the options we chose while
we are in the fdisk mode.
create a partition in Linux with gparted
# sudo apt-get install gparted
# gparted
Graphical Interface

fdisk is a simple text-based partitioning utility.-to partition the primary SATA disk
$ sudo fdisk /dev/sda
m (m-help)
p (p- to display the current partition)
n (n- to create a new partition)
e (e- extended)
3 (partition number)
p (p- to display the current partition)
d (to delete a partition)
3 (what we have created)
q (quit)
w (save and quit)
4) To create a script that shows the user that are logged, the processes started by the users, how
long the session is running and the job should be scheduled in crontab and anacron. While the
job is running in crontab to show the result in the monitor.

SCRIPT
1-Create the script
$ sudo nano /home/Ubuntu/Desktop/script1.sh
Or
$ sudo nano script1.sh
--------
#!/bin/sh
who (shows the user that are logged)
ps –el (the processes started by the users)
ps –u jane
ps –f –pid $(pgrep –u “jane”) (informacion me I detajuar)
last -1 jane

---------------
2-change the permission of the script (made it executable)
$ sudo chmod 777 ~/Desktop/script1.sh
3-Execute the file
$ . ~/Desktop/script1.sh

CRONTAB JOB
4- Adding it in a crontab job
$ sudo nano /etc/croshow tab (nuk perdoret) (or)
$ sudo crontab –e
--------
* * * * * /bin/sh home/ubuntu/Desktop/script1.sh
--------
5- in another terminal see the no of the monitor driver
$ tty
( we will see /dev/pts/17)
6- adding it in the crontab job
$ sudo crontab –e
--------
* * * * * /bin/sh home/ubuntu/Desktop/script1.sh >/dev/pts/17
--------
7- kontrollo statusin the resarto cronjob
$ systemctl status cron
$ systemctl restart cron

s
ANACRON JOB
8- (always as a root)
$ sudo -i
#
9- move the script1 in the path /var/spool/anacron
# mv /home/ubuntu/Desktop/script1.sh /var/spool/anacron
10- ekzekuto scriptin
# . /var/spool/anacron/script1.sh
11- adding it in anacronjob
# nano /etc/anacrontab
--------
1 1 test.daily /bin/sh /var/spool/anacron/script1.sh
>/home/output (we don’t have the test.daily yet)
--------
12- power-off the PC
(shohim nese run-ohet per 2 min mbas ndezjes)
13-per Informacion
# grep START /etc/anacrontab

5) To create a script that generates some empty file where in the filename is the timestamp of the
moment where the file is generated by the script scheduled in crontab. To create another script
that deletes the files generated by the previous script before a certain hour.

SCRIPT 1
1-Create the script
$ sudo nano script1
--------
#!/bin/sh
touch “test.txt_$(date +”%Y%m%d_%H%M%S”)”
---------------
2-change the permission of the script (made it executable)
$ sudo chmod 777 ./script1
3-Execute the file
$ . ./script1 (ose . /script1)

CRONTAB JOB
4- Adding it in a crontab job
$ sudo crontab –e
--------
*/1 * * * * /bin/bash home/ubuntu/script1
--------
5- in another terminal see the no of the monitor driver
$ tty
( we will see /dev/pts/17)
6- adding it in the crontab job
$ sudo crontab –e
--------
* * * * * /bin/bash home/ubuntu/script1 >/dev/pts/17
--------
(teorikisht do te gjenerohen automatikisht)

7- kontrollo statusin the restarto cronjob


$ systemctl status cron
$ systemct restart cron

8-kontrollo filet e gjeneruars


$ ls –lrt
SCRIPT 2

8-krijojme nje script tjeter


$ sudo nano script2
--------
#!/bin/sh
find . –type f –name “test.txt”_20190131_16*” –exec rm –rf {}
\;
---------------
2-change the permission of the script (made it executable)
$ sudo chmod 777 ./script2

6- adding it in the crontab job and canceling the first script duke vendosur nje #
$ sudo crontab –e
--------
# * * * * * /bin/bash home/ubuntu/script1 > /dev/pts/17
* * * * * /bin/sh home/ubuntu/script2
--------
7-kontrollo nese filet e gjeneruara jane fshire
$ ls –lrt

To tell how we can


schedule a job in crontab and how we do it in Windows just the procedure not to write any file
in notepad saving it with bat and running it, just in Windows how we schedule a job.

Vous aimerez peut-être aussi