Ubuntu Notes
Ubuntu Notes
when a directory name occurs in several places. Fortunately, Linux includes a simple com-
mand that tells you exactly where you are in the file system. It’s easy to remember that
this command is pwd because it is an abbreviation of print working directory. You simply
type pwd at any point to get the full path of your location. For example, typing pwd after
following the preceding instructions shows /home/yourusername, meaning that you are
currently in your home directory.
Using the pwd command can save you a lot of frustration when you have changed directory
half a dozen times and have lost track of where you are.
Creating users
A user is anyone who uses or operates the system.
There are two ways to create a user
1. Adduser 2. Useradd
With user add, you’ll have to create the directories that come with it. It is usually used by experts to customize the system.
Sudo adduser newusername
PERMISSIONS
There are three permissions we give to files and directories.
1. Read – being able to see the content of the file. R 4
2. Write – being able to modify content of the file. W 2
3. Execute – could contain a program setup or link which you can execute. X 1
4. Read and write – 6
5. Read and execute – 5
6. Write and execute – 3
7. Read, write and execute – 7
There are three categories of people that we can give the permissions to
1. owner - u 2. group - g 3. others - o
The command that can give us detailed information about a specific file, directory or the command – (ls -l)
To give the owner permission to execute,
u+x
u owner
+ to add a permissions
x execute permissions
The only can only read, the group can only read and execute and the others can
mmanuella@emmanuella-HP-EliteBook-840-G2:~$ touch emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ ls -ld emmanuella
-rw-rw-r-- 1 emmanuella emmanuella 0 K-Ɔ 16 08:44 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ chmod 775 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ ls -ld
drwxr-x--- 18 emmanuella emmanuella 4096 K-Ɔ 16 08:44 .
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ ls -ld emmanuella
-rwxrwxr-x 1 emmanuella emmanuella 0 K-Ɔ 16 08:44 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ chmod 555 emmanuellaayerh
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ ls -ld emmanuella
-rwxrwxr-x 1 emmanuella emmanuella 0 K-Ɔ 16 08:44 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ chmod 555 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ ls -ld emmanuella
-r-xr-xr-x 1 emmanuella emmanuella 0 K-Ɔ 16 08:44 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ umask 002 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ ls -ld emmanuella
-r-xr-xr-x 1 emmanuella emmanuella 0 K-Ɔ 16 08:44 emmanuella
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ umask
0002
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ umask 022
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ umask
0022
You cannot delete a primary group unless you delete the secondary groups
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ sudo addgroup computerscience
[sudo] password for emmanuella:
Adding group `computerscience' (GID 1004) ...
Done.
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ usermod -G computerscience
Usage: usermod [options] LOGIN
change group – chgrp ; you can use this command to change a group to which a file belongs
chown – to change the owner of a file.
Don’t put spaces on either sign of the equal sign when assigning a variable. X = 10 is wrong. It will be seen as a command and not a variable.
Variables are case sensitive.
You can define a null variable as follows. eg. boss=””
Do not use question mark, asterisk and other symbols to name your variables. A wild tag
How do you print and accesds a command. What is the echo used for – for printing a variable or value etc
What is the difference between echo x and echo $x? The dollar sign prints what is in the variable. If not it will just print x.
Operators
To display, ./MyFirst
The set command is used to access system variables.
Introduction to kernel
The kernel is the HEART of the linux operating system. Without it, the operating system is useless. It manages the resources of the operating system,
eg. the facilities to store data, printing, memory allocation, file management etc. It is the kindle that decides who will use a particular resource, how
long it will be used and when access will be given to use that resource. The uses of the kernel are summarized into five functions.
1. Input-output management
2. Process management
3. Device management
4, File management
5. Memory management
From the above picture we are using the Bourne Again Shell (bash).
How do we use this shell?
You start using the shell as long as soon login to your system. It was translating our commands into computer readable form.
There is a command that will tell us more apart from the man command.
So, you type the command name , space, double hyphen and help. COMMAND_NAME –help
Since it is too much, we can add a command MORE so that we can view it line by line.
Another one is info but it come before the command. Info will not display in the same screen of the same terminal. You can press q to quit.
PROCESSES
A process is any kind of program or task carried out by your computer.
1. ls -IR
It requests to name files in the directory and all subdirectory based on your current directory.
IN LINUX immediately you start a process, it is assigned a process ID (PID) It starts from 0 to 65535.
So why is a process required?
Ubuntu Linux is a multi-user and multitasking operating system. You can run two or more processes simultaneously and two or more users can use it at
the same time.
To stop any process, we use the command kill. You can use the name of the process or the process ID.
Kill is used for stopping processes that are running in the background.
To get information about all running processes, use ps -ag. It lists processes and their description.
To stop all processes except your shell, use kill 0.
Note that you can only kill processes that you created yourself not those created by the kernel unless you are an administrator or a sudo user where you
can kill some processes.
1. >
Syntax - linux_command > filename
To output linux command results to file, command > filename.
If you want to append the file and not override it, ls >> file.
The less than sign is used to receive input.
PIPES
A pipe is a a way to connect the output of one program to the input of another program without any temporary file. Redirectors output the commands in
a file but in this case, we have two processes and the output of one will be the input of the other one.
A pipe is nothing but a temporary storage place where the output of one command is stored and then passed as the input for the second command.
Syntax
command1 | command2
Output of the ls –help will be given as input to the more command. The ls --help information is to be shown MORE.
The who command shows the user who is logged in at the moment.
Piping who into sort will print the sorted list of users.
The wc command shows us the number of users who are logged into the system.
The output of the who command is given as input to the wc command so that it will display the number of users who are logged on to the system.
This will show the number of files or directories in the current directory.
Grep command is used to search for a command like a filter tool. If the user is logged on at the moment the name of the user will show else nothing
will happen. NOTE The space is very important.
FILTER
If a linux command accepts its input from a standard input and produces its output on a standard output, it is known as a filter.
Standard input is any approved way of giving an input to a system and the results from them is standard output. A filter performs some kind of
processes on the input and produces an output that the user wants to see out of the lot.
The filter performs processes on the input and gives an output. It created the file called example which was not in existence and put the command in
there.
VARIABLES IN LINUX
Sometimes to process our data or information, it must be kept in the computer’s RAM. Ram is divided into small locations and each location is having
a unique number called MEMORY LOCATION or MEMORY ADDRESS, which is used to hold our data. A programmer can give a unique name to
this memory location or address called memory variables or VARIABLES. There are two types of variables
1. System variables
These are variables that are created by the system – linux itself. They are defined in CAPITAL LETTERS.
Examples
You can view all the system variables with the command SET. To find the type of shell that you are using.
The files starting with a dot are hidden files which usually contain system configuration files. A cron job is a command in linux which schedules a
command to be executed in the future.
ls -al include details such as the file/directory permissions, owner and group, size, and the date and time it was last modified.
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ cd Desktop
emmanuella@emmanuella-HP-EliteBook-840-G2:~/Desktop$ pwd
/home/emmanuella/Desktop
emmanuella@emmanuella-HP-EliteBook-840-G2:~/Desktop$ cd ..
emmanuella@emmanuella-HP-EliteBook-840-G2:~$ pwd
/home/emmanuella
To change the group of a file or directory, use chmod newgrp filename.
Working from a text-only system is useful both for working locally with a broken GUI and
for connecting to a remote, text-only system. If your Linux server is experiencing prob-
lems, the last thing you want to do is load it down with a GUI connection; working in
text mode is faster and more efficient.
Many other commands are also used fairly often—cut, diff, gzip, history, ping, su, tar,
uptime, who, and so on—but if you can understand the ones listed here, you have suffi-
cient skill to concoct your own command combinations.
The most popular parameters for customizing the output of ls are as follows:
▶ -a—Includes hidden files
▶ -h—Uses human-readable sizes
▶ -l (lowercase L)—Enables long listing
▶ -r—Reverse order
▶ -R—Recursively lists directories
▶ -s—Shows sizes
▶ --sort—Sorts the listing