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
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
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.
also the command to lock the root user after you have added the user to the pool of superuser.
# sudo adduser ganiela sudo (ose) # usermod -aG sudo ganiela
# sudo passwd –l root (to lock the root user) (to disable root
account)
# sudo passwd –lock ganiela (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
echo “The actual user is: $USER”
top –U $USER (or)
who (shows the user that are logged)
ps –el (the processes started by the users)
ps –u ganiela
ps –f –pid $(pgrep –u “ganiela”) (informacion me I detajuar)
last -1 ganiela
---------------
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)
--------
Or
--------
@daily 7 cron.daily /bin/sh /var/spool/anacron/script1.sh
>/dev/pts/1
--------
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)
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