How to run commands in Terminal for a Linux computer operating system and other programs.
This tutorial file is for hands-on learning by running the commands. Read the instructions, follow the examples and run the commands. The text is a bit repetitive with a lot of computer output in the examples. But do not edit it as it is written in a style for easy cutting and pasting of commands into Terminal.
Search this file for key words leading to the commands you want to run. Think of a search word which describes what you want to do then find it on this page.
To skip from one command to the next, search case-sensitively for the word To.
To download this web page from the internet:
Open the page in a web browser.
Right click it with the mouse and save it into the downloads directory on your computer.
Move the web page to a directory where it is to be kept.
Right click the name of the html file and select to open it in a plain text editor, not a web browser, word processor or web publisher.
To find the information wanted:
Open this file in a plain text editor like Nano, Vi or Gedit.
Select find, search for a key word or words.
To search this file with Gedit:
Open this file in gedit.
Click the three-line button at top right.
On the drop list, select find.
user:~$ gedit ~/Desktop/linuxsudo156
user:~$
linuxsudo156 file is open.
Click the notepad icon at left to show the window.
Click the three-line icon at top right and select find.
Type in a key word like a command or other word to tell the editor what to look for.
Here in this example the keyword is swap.
Find shows that word too many times.
So add another word, say swap partition.
That search leads to swap commands like mkswap .
To search for two or more words in gedit, type words which are together in the text.
Do not put words within quote marks or gedit will search for the quotes and not find anything.
To skip most of the theory in this tutorial and scroll from one practical example or command to the next:
On the top search menu bar in Gedit, select find.
Click the magnifying icon and in the drop list tick match case.
Search for the word "To " which starts each example.
Click the search down arrow to scroll.
To use this Linux tutorial:
Open this tutorial in a plain text editor.
Drag the window of the editor to the right side of the page.
Open Linux Terminal program.
Drag terminal to the left side of the page.
Copy Linux commands from the tutorial and edit and run them in the terminal.
To keep a log for reference:
Copy lines of output in Terminal and paste them into a plain text file.
Linux tutorial
A superuser, su, is the administrator of a computer network. A superuser can run a sudo command to tell a computer to do something.
The su is the root user and his password for commands is the same password he has used to install the Linux program unless somebody else has installed it.
To check a user's password:
user@user-K-ED4:~$ su
Password:
su: Authentication failure
Ubuntu disables the root su password by default. Type sudo before commands instead of su.
username@username-ID:~$ su username
Password:
username@username-ID:~$
Ubuntu accepts the su admin password of that user.
To open a sudo command line, run this command:
user@user-K-ED4:~$ sudo -i
root@user-K-ED4:~#
See that the command prompt now ends with # not $.
Do not type su or sudo commands after a # hash prompt while you are learning Linux. Instead after a $ dollar prompt type sudo followed by the rest of the command.
To log out of the # prompt and go back to the $ user prompt, type exit and press return:
# exit
A shell is a command line where you type commands. Shell scripts are groups of Linux commands.
When working on the command line, you usually want to work with the default permissions. This way you make sure you do not accidentally break anything belonging to the system or other users. Yet there will be times when you wish to copy a file to a system folder, like to /usr/local/bin to make it available to all users of the system. Only a system administrator, root, should have permission to alter the contents of system directories like /usr/local/bin. So trying to copy a file like a program downloaded from the internet, into that folder is forbidden by default.
To start Terminal, press ctrl-alt-t. On the top menu bar, go to edit, preferences and tick highlight current line. The highlight helps find the cursor quickly.
To run a command as the administrator, as the root user, type or cut and paste the sudo command at the command line after the $ or # mark.
A command is typed after a prompt on a command line, which looks like this:
robert@robert-H87A-UD5:~/Backups$ tar -cf deskback.tar ~/Desktop/*
The first part of the line up to the $ sign is the command prompt. The command is typed after the prompt. Here Robert is the name that the user of the computer typed when he installed the Linux operating system. The second name is the name of the group of users he belongs to and is often the same name as that of the user. Then there is a user code. Then ~/Backups is the name of the present directory of files. The dollar $ sign indicates that the command line is in ordinary user mode, not in root administrator or superuser mode which would be indicated by a hash # sign instead of a $. After the dollar, the command itself begins with the name of a program. Here the program is called Tar. Options often follow next as a hyphen - followed by letters, each letter being another option. The options above are -cf, which tell the command tar to create a file. Arguments often end the command. Here the arguments are deskback.tar ~/Desktop/* . These arguments tell tar the name of an archive file to be created and what files to put into that archive. Here the files are to be copied from a directory called `/Desktop. The asterisk * says all the files in the directory.
To write and run Linux Bash shell scripts:
This file shows how to run Linux commands and write scripts. Search for a key word to find a command or script or a description of what a command does and how to use it. The file has many words of jargon as keywords to help find what is wanted. Cut and paste command lines into Terminal. Do not worry about the jargon as you read the notes of explanation throughout this file. A $ or # sign usually marks the end of a command prompt where you start to type the command and is not usually part of a command itself. The word "user" below means the name of the user of the computer and, like the dollar or pound or hash sign, it is not usually part of a command. Examples in this tutorial often run different commands that do much the same jobs. Choose whichever commands you want to run.
Format is a DOS command; see fdformat instead.
To show a list of all the programs running on the computer system, run the ps command:
yne@user-Inspiron-N5030:~$ ps a
PID TTY STAT TIME COMMAND
961 tty7 Ss+ 0:06 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/ru
964 tty1 Ss+ 0:00 /sbin/agetty --noclear tty1 linux
2093 pts/3 Ss 0:00 bash
2110 pts/3 R+ 0:00 ps a
user@user-Inspiron-N5030:~$
To close all programs and shut down the computer from the Linux Terminal command prompt, type
init 0 and press the enter or return key.
To show the size of each file in the current directory, list them with the -s option:
user@user-U-H:~/Desktop/testfold$ ls -s
total 9064
4 bugtest 8 errors 4 ipdetect 292 quailprice.png 8756 tibet.mp3
Bash program often is the command interpreter for Linux by default and it is called a shell. When a command is typed and run in Terminal, Bash interprets and executes that command. It cannot interpret commands unless they are written right for it.
Shell commands can be combined by piping one command into the next with the pipe | , which is shift \ backstroke on a keyboard. Piped or redirected commands have > more than or less than < characters typed in them.
To finish typing a long file name, use the Tab key as follows.
user@user-Inspiron-N5030:~$ cd ~/Desktop
user@user-Inspiron-N5030:~/Desktop$ ls
linuxsudo wifisudo
To edit the file called wifisudo, type gedit wif then press tab. Bash automatically finishes typing the filename and opens the file with the Gedit text editor.
user@user-Inspiron-N5030:~/Desktop$ gedit wifisudo
user@user-Inspiron-N5030:~/Desktop$
Linux
GZIP(1) General Commands Manual GZIP(1)
NAME gzip, gunzip, zcat - compress or expand files
SYNOPSIS
gzip [ -acdfhklLnNrtvV19 ] [--rsyncable] [-S suffix] [ name ... ]
gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ... ]
zcat [ -fhLV ] [ name ... ]
DESCRIPTION
Gzip reduces the size of the named files using Lempel-Ziv coding
(LZ77). Whenever possible, each file is replaced by one with the
extension .gz, while keeping the same ownership modes, access and modi‐
The kernel is the core of the Linux operating system which is included with other programs to form a Linux distribution such as Ubuntu or Fedora. Bash is the default shell program in most distributions.
A prompt for a command line shows the username and ends in a $ sign. A command is typed after the $. Open the program called Terminal to see a shell command prompt.
Normally do not use a virtual console to run commands.
To open or start a virtual console instead of Terminal, type CTRL-ALt-F1 (or F2 to F6) Then type username at the prompt and press enter or return, then type user password to open the console. Then you have a command prompt $. When finished, type exit and enter. CTRL-Alt-Del will restart your computer. To close a virtual consol type ctrl-alt-F7. Ctrl-Fn means press control key and a function key together, n being the number of the key 1 to 7 or 8. Linux usually has 7 to 8 consoles or virtual terminals, VTs.
To open a virtual terminal VT instead of a graphic terminal, type Ctrl-Alt-F1. To quit without entering a username or password, press ctrl-alt-F7. To login, type your username and press enter or return, type your password and press enter. To quit, exit or logout, type logout and press enter. That opens and closes a Bash terminal in text mode.
To open an interactive root shell, that is a window where you type only sudo commands, type sudo -i
wae@wae-GCM-S2L:~/Documents$ sudo -i
[sudo] password for user:
Enter administrator's password
root@user-945GCM-S2L:~#
A command prompt in a root shell, for an administrator, ends with hash, #. A command prompt in a normal terminal window for both administrators and other users ends with a $ sign.
To log in as administrator: $ sudo -s
or sudo bash
then # type password
user@user-M-ED4:~$ sudo -s
[sudo] password for user:
root@user-M-ED4:~#
If there is only one user on a computer, that user is the administrator and he can use the same password as user or administrator, the password he set when he installed Ubuntu.
To go back to the $ command prompt, type exit and press enter or return.
root@user-M-ED4:~# exit
exit
user@user-M-ED4:~$
To log in as another user, type
sudo -i -u otherusername
then type the administrator password.
To start or open the graphic GUI Terminal program in Ubuntu16:
Click the black Terminal icon in the programs list,
or the orange A software icon, find Terminal, run or install it if need be, and lock the icon to the program bar.
To open another new tab or terminal window:
Click file on top menu then click open tab or open terminal in drop list.
To close a terminal window or tab, type exit as a command.
To type and run a command in Terminal, mouse-click the rectangular cursor to make it flash after the $ or > sign then type the command and press the enter key. User command prompts in some terminals end with a > instead of a $.
To show a description of a program:
$ type programname
user@user-M-ED4:~$ type alias
alias is a shell builtin
user@user-M-ED4:~$
To open a directory type cd and the address of the directory. For example the command $ cd ~/Desktop will open the subdirectory called Desktop in the home directory ~ . Leave a space between the $ or # prompt and the command and another space between the command and the directory. Commands are case sensitive; capital D for Desktop. The backstroke \ must be typed in a command although the forward stroke / is shown in a prompt line.
user@user-M-ED4:~$ cd ~/Desktop
user@user-M-ED4:~/Desktop$
Here the ~ sign is short for /home/userdirectory/. The full name for the directory is /home/username/Desktop.
To restart and reboot the computer:
sudo reboot
First save files and close programs.
wae@wae-GCM-S2L:/$ sudo reboot
[sudo] password for user:
Type password and press enter.
To go back or change to the home directory type
cd ~
or to go to root directory, cd /
user@user-M-ED4:~$ cd ~/Desktop
user@user-M-ED4:~/Desktop$ cd ~
user@user-M-ED4:~$ cd /
user@user-M-ED4:/$
To list show all files in the current directory which are of the same type:
Use the wildcard * asterisk.
Here the filenames all end with .png; .png files.
user@user-U-H:~/Desktop/testfold$ ls *.png
quailprice.png
There is only one such file.
The List command does not find text files using the wildcard because that Linux system does not show .txt extensions.
Grep is a program run in Terminal that finds key words within a file.
To start and run Grep and find the keywords "Bus Proxy" in a file called passwd which is in the directory called /etc: -
after the $ sign type grep "Bus Proxy" /etc/passwd
Quote marks are needed in the command if the search term has any space in it.
user@yne3:~$ grep "Bus Proxy" /etc/passwd
systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false
user@yne3:~$
The output is the line above containing the keywords.
A grep search through a directory and its many subdirectories can take time; wait. If you need to cancel a search, type ctrl-alt-\ and press enter to quit and go back to a command prompt.
To recursively -r search through a directory and all its subdirectories for files mentioning a word:
First change to the directory then use the grep command with its -r option. Also you can use the -i option to ignore whether the search word is in upper or lowercase, the capital -H option to print the file name for each match, or the -l option to print only the names of files containing matches. Here the word being searched for is "chat".
commandprompt:~/Documents$ grep -ril "chat" ./
./thunderbirdc
./ubuntu-server.log
./ab19818b
./namesb
./chatthunderbird
etc ..
./webchat
./webchatirc
...etc
./xchat/xchat
./xchat/XCHAT FAQ.html
./optuscomplaintchat419
commandprompt:~/Documents$
The search word was found recursively -r in the current directory and one of its subdirectories, /xchat.
To search for a key word and print out the sentences having that word in it, use grep with the -H option:
commandprompt:~/Documents$ grep -riH "chat" ./
That found the word "chat" in copied chat conversations.
eg ./xchat/xchatcb:To see chat conversation, start chatting by entering and sending text. The chat window will remain blank until you (or another person) speaks.
Gzip is a utility program for compressing and decompressing files. Zip does much the same job.
less - displays data page by page
info - displays online help and usage information about any command.
To see the encrypted password of the administrator:
user@yne3:/etc$ sudo grep root /etc/shadow
root:!:17884:0:99999:7:::
user@yne3:/etc$
Root is the admin and the number is his encrypted password.
A password cracking program can run this number to match it with a password.
To hide a file so that it does not usually show in a list of files:
Here in a testfolder is a file called testlist to be hidden.
user@user-U-H:~/Desktop/testfold$ ls
bintest fruitsale listtest tdout testlistk
codetest fruitsale2 memotest testlist testlistk2
dtop listcut.txt memotestc testlist2 testtouch.txt
Use the move command to rename the file, starting its name with a full stop:
user@user-U-H:~/Desktop/testfold$ mv testlist .testlist
user@user-U-H:~/Desktop/testfold$ ls
bintest dtop fruitsale2 listtest memotestc testlist2 testlistk2
codetest fruitsale listcut.txt memotest tdout testlistk testtouch.txt
A file called testlist or .testlist is no longer listed.
To list and show a hidden file, use the list command with the show -all files option.
user@user-U-H:~/Desktop/testfold$ ls -a
. codetest fruitsale2 memotest .testlist testlistk2
.. dtop listcut.txt memotestc testlist2 testtouch.txt
bintest fruitsale listtest tdout testlistk
There is the hidden file with its name starting with a dot.
To hide a folder from the files manager program:
cathy@cathy-hostname:~$ sudo mv ./Desktop/ ./.Desktop/
cathy@cathy-hostname:~$ ls
Documents examples.desktop Pictures Templates
Downloads Music Public Videos
cathy@cathy-hostname:~$
To show a longer -l list of more information about a file:
Here the full name of the file is forgotten so use a wildcard * .
user@user-U-H:~/Desktop/testfold$ ls -l quail*
-rw-rw-r-- 1 user user 296180 Jun 20 16:15 quailprice.png
user@user-U-H:~/Desktop/testfold$
Ubuntu does not usually show the .txt extension of a text file even with the ls -p for append option.
user@user-U-H:~/Desktop/testfold$ ls -p fruitsale
fruitsale
To show the first few lines of a file, use the head command.
user@user-U-H:~/Desktop/testfold$ head -n 5 fruitsale
Apples are crisp. $4
Bananas taste nice when soft when ripe. $1
user@user-U-H:~/Desktop/testfold$
Although the command says show 5 lines, the first 3 lines are blank.
To read info about a command: -
Here grep is the command to be read about.
user@yne3:~$ info grep
This manual is for ‘grep’, a pattern matching engine.
* Menu:
* Introduction:: Introduction.
* Invoking:: Command-line options, environment, exit status.
* Regular Expressions:: Regular Expressions.
* Usage:: Examples.
* Reporting Bugs:: Reporting Bugs.
* Copying:: License terms for this manual.
* Index:: Combined index.
Press q to return to command prompt.
man - shows the user manual for a program.
yne-K-ED4:~$ man gzip
GZIP(1) General Commands Manual GZIP(1)
NAME gzip, gunzip, zcat - compress or expand files
SYNOPSIS gzip [ -acdfhklLnNrtvV19 ] [--rsyncable] [-S suffix] [ name ... ]
gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ... ]
zcat [ -fhLV ] [ name ... ]
DESCRIPTION
Gzip reduces the size of the named files using Lempel-Ziv coding
(LZ77). Whenever possible, each file is replaced by one with the
extension .gz, while kee ...
Press q to return to the command prompt.
To find information about programs, type the command whatis followed by a key word.
user@yne3:~$ whatis cat
cat (1) - concatenate files and print on the standard output
user@yne3:~$
To show what files are in a subdirectory of the current directory, type a full stop to mean current:
jack@jack-U-H:~/Desktop$ ls ./testfold
output
jack@jack-U-H:~/Desktop$
One file called output is in the subdirectory called /testfold.
To type output for the screen, run the cat command alone, without any variables. Cat shows a blank space to type in. Type what you want. Press ctrl-\ to quit.
Standard input is jargon for what you type on the keyboard, standard output is what that input says on the screen.
jack@jack-U-H:~/Desktop$ cat
This is output typed on the keyboard and seen here on screen.
^\Quit (core dumped)
jack@jack-U-H:~/Desktop$
Type trl=\ to quit Cat.
To redirect output from a command to a text file, use this redirect sign >:
jack@jack-U-H:~/Desktop$ ls -al > ./output
jack@jack-U-H:~/Desktop$ gedit ./output
Look at the open output file in Gedit. Output from the list command ls has been printed into the file called output.
total 2244
drwxr-xr-x 3 jack jack 4096 Jun 27 10:02 .
drwxr-xr-x 26 jack jack 4096 Jun 27 07:12 ..
-rw-rw-r-- 1 jack jack 250 Jun 27 09:24 2DO
-rw-rw-r-- 1 jack jack 122 Jun 15 17:52 georgeuser
-rw-rw-r-- 1 jack jack 788 Jun 26 12:53 ipdetect
-rw-rw-r-- 1 jack jack 959 Jun 23 19:20 irclink
-rw-rw-r-- ... etc
Each time you send more output to the same filename, the new output replaces the old file of the same name.
To redirect output from a command so that the new ouput is added to old output in an old file instead of replacing it, use a double redirect sign >> :
jack@jack-U-H:~/Desktop$ echo Add this output to the output file. >> ./output
jack@jack-U-H:~/Desktop$ cat ./output
total 2244
drwxr-xr-x 3 jack jack 4096 Jun 27 10:02 .
drwxr-xr-x 26 jack jack 4096 Jun 27 07:12 ..
-rw-rw-r-- 1 jack jack 250 Jun 27 09:24 2DO
-rw-rw-r-- 1 jack jack 122 Jun 15 17:52 georgeuser
... etc
-rw-rw-r-- 1 jack jack 3836 Jun 26 20:47 xargstest
Add this output to the output file.
jack@jack-U-H:~/Desktop$
There output from the echo command was added after earlier output from the list command in the same file called output.
To redirect output from a cat command to a file:
jack@jack-U-H:~/Desktop$ cat >> ~/Desktop/output
This is text output from a cat command redirected to a file called output.
.
There you type your message into a blank space, press enter then full stop . then enter again, then ctrl-d to deliver the output. To show what is in the output file, use cat this way.
jack@jack-U-H:~/Desktop$ cat ~/Desktop/output
total 2244
drwxr-xr-x 3 jack jack 4096 Jun 27 10:02 .
drwxr-xr-x 26 jack jack 4096 Jun 27 07:12 ..
-rw-rw-r-- 1 jack jack 250 Jun 27 09:24 2DO
-rw-rw-r-- 1 jack jack 122 Jun 15 17:52 georgeuser
... etc
-rw-rw-r-- 1 jack jack 3836 Jun 26 20:47 xargstest
Add this output to the output file.
This is text output from a cat command redirected to a file called output.
.
jack@jack-U-H:~/Desktop$
To redirect error messages away from the screen and into a text file:
Here we can make a file called errors.
jack@jack-U-H:~/Desktop/testfold$ gedit errors
Save this file into the current directory.
jack@jack-U-H:~$ find /var/mail/ -name 'jack.*' 2>~/Desktop/testfold/errors
The 2 means errors. Errors is 2, input is 0 and output is 1.
This error message was redirected to the errors file.
find: ‘/var/mail/jack.*’: No such file or directory
This next redirect sent a CC: error into the errors file.
jack@jack-U-H:~$ mail 2 > ~/Desktop/testfold/errors
To find all the files of a kind in a current directory and its subdirectories, redirect the output to xargs and delete those files:
$ find ./ -name "*out*" | xargs rm
That deletes all files with out in their names.
jack@jack-U-H:~/Desktop/testfold$ ls
errors
output
outputb
quailprice.png
The Seven Letters From Tibet 04. The Green Land.mp3
jack@jack-U-H:~/Desktop/testfold$ find ./ -name "*out*" | xargs rm
jack@jack-U-H:~/Desktop/testfold$ ls
errors
quailprice.png
The Seven Letters From Tibet 04. The Green Land.mp3
jack@jack-U-H:~/Desktop/testfold$
Those two output files are removed.
To redirect the output of one command to the input of another command, you can use a pipe | between the two.
user@user-U-H:~$ echo "How many words and characters are in this text message?" | wc
1 10 56
user@user-U-H:~$
The text there was piped redirected from the echo command into the word-count command.
To change to another directory:
jack@jack-U-H:~$ cd ~/Desktop/testfold
jack@jack-U-H:~/Desktop/testfold$
To go back one directory:
cd ..
To go to the root directory, type a forward sroke:
cd /
commandprompt:~$ cd /
commandprompt:/$ cd ~
commandprompt:~$
To go to the home directory:
cd ~
type a tilde as above.
To go back to a command prompt after a mistake, type exit and press return.
commandprompt:~$ cd \
> exit
bash: cd: exit: No such file or directory
commandprompt:~$
To shut down the bash program, type this command and enter the admin password:
$ sudo shutdown now
Bash closes and the computer stays on.
To start Ubuntu, press ctrl-alt-del
To stop the computer, press and hold the start button in.
To change to the home directory on another hard drive:
Here the long name of the other hard drive is shortened by typing an * asterist.
user@user-hostname:/$ cd /media/user/c4931570*/home/user/
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user$ ls
Documents examples.desktop Music Programs Scripts Videos
Desktop Downloads Pictures Public Templates
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user$
Ubuntu by default mounts separate hard drives at /media/username/
To list the contents of a directory:
ls
jack@jack-U-H:~/Desktop/testfold$ ls
errors
quailprice.png
The Seven Letters From Tibet 04. The Green Land.mp3
jack@jack-U-H:~/Desktop/testfold$
To make a new directory:
$ mkdir
To rename a file and or move it to another directory, the command is mv:
mv
To remove and delete a directory:
rmdir
jack@jack-U-H:~/Desktop/testfold$ rmdir ~/Music/fol*
That removed every subfolder with fol in its name from the /Music directory.
jack@jack-U-H:~$ ls ~/Music
jack@jack-U-H:~$
To show the present current directory:
jack@jack-U-H:~$ pwd
/home/jack
jack@jack-U-H:~$
To find a file with a keyword in its name. The key word here is "sudo". First update the data base as shown below.
locate
user@yne3:~$ locate -iqwe sudo
/etc/sudoers
/etc/sudoers.d
/etc/pam.d/sudo
/etc/sudoers.d/README
/home/user/.sudo_as_admin_successful
/home/user/Documents/foremostsudo
/home/user/Documents/foremostsudob
/home/user/Documents/sudorepos
/home/user/Documents/encrypt/sudogpg ... etc
The -i option tells Locate not to be case sensitive for upper or lower case letters.
The -e option tells Locate not to show the names of files deleted since its data base was last updated.
The -w for wholename says to match only the whole path name.
Option -q means quietly without showing errors.
To first update the data base of filenames which Locate uses:
sudo updatedb
user@user-M-ED4:~$ sudo updatedb
[sudo] password for user:
user@user-M-ED4:~$
To locate and find a file with a search term in its name,
here the search term is between asterisks:
user@user-M-ED4:~$ locate *sb9619*
/home/user/Desktop/sb9619
/home/user/Desktop/sb9619.png
/home/user/Desktop/sb9619pm.png
/home/user/Desktop/sb9619rep.png
user@user-M-ED4:~$
To find which database Locate is using, use an -S option:
user@user-M-ED4:~$ locate -S
Database /var/lib/mlocate/mlocate.db:
17,016 directories
200,737 files
10,719,255 bytes in file names
4,807,835 bytes used to store database
user@user-M-ED4:~$
To locate a file by its exact file name:
$ locate filename
user@user-M-ED4:~$ locate bb9619.png
/home/user/Desktop/bb9619.png
user@user-M-ED4:~$
Locate finds files in all directories, not just the current directory.
Or to be more exact also use a regular expression as below.
To locate only the file with its exact name, use the -r regular expression $ like this:
locate -r /filename.extension$
user@user-M-ED4:~$ locate -r /oldcarkey.jpg$
/home/user/Desktop/oldcarkey.jpg
user@user-M-ED4:~$
The $ character used as a regular expression matches the end of a line.
To find where a program file, that is an executable or binary file, is:
whereis
yne@yne3:~$ whereis grep
grep: /bin/grep /usr/share/man/man1/grep.1.gz /usr/share/info/grep.info.gz
user@yne3:~$
Grep is the name of the program searched for.
To show the full pathway to the current directory, run pwd.
To type a command that is too long to fit on one line in Terminal, go to the next blank line by typing a backlash / then pressing enter key, then type the rest of the command, ending each broken line with /.
To link two or more commands together and run or execute them one after the other, type them separated by semicolons.
user@yne3:~$ cd; ls -l; pwd
total 72
drwxr-xr-x 3 user user 4096 May 25 13:42 Desktop
drwxr-xr-x 11 user user 12288 May 24 16:01 Documents
drwxr-xr-x 2 user user 20480 May 16 14:11 Downloads
-rw-r--r-- 1 user user 8980 Dec 19 11:30 examples.desktop
drwxr-xr-x 2 user user 4096 Dec 19 11:35 Music
drwxr-xr-x 2 user user 4096 May 3 13:23 Pictures
drwxrwxr-x 3 user user 4096 Mar 22 10:03 Programs
drwxr-xr-x 2 user user 4096 Dec 19 11:35 Public
drwxr-xr-x 2 user user 4096 Dec 19 11:35 Templates
drwxr-xr-x 2 user user 4096 Dec 19 11:35 Videos
/home/user
user@yne3:~$
cd alone changes from the current directory to the home directory; ls lists the directories and files in that directory; and pwd shows the pathway of the directory, that is /home/user.
To show or display the contents of a file:
cat
cat filename.extension
wae@host-5G-S2L:~/Documents$ cat vistause.txt
or $ cat /directory/filename
ne@yne3:~$ cat ~/Desktop/grep
Grep is a program run in Terminal that finds key words within a file.
‘grep’ prints lines that contain a match for a pattern. ... etc
To link shell commands or pipe one into another, type a pipe |, which is on the backlash key.
To go to a directory that contains pages of file names then find a file that contains a keyword or string of characters in its filename, use a pipe to grep.
ls /directoryname | grep keyword
i2c-8 ram15 stdout tty44 ttyS22 video0
i2c-9 ram2 tty tty45 ttyS23 zero
initctl ram3 tty0 tty46 ttyS24
user@yne3:~$ ls /dev | grep port
parport0
port
user@yne3:~$
Port is the keyword or string.
To see what version of Linux kernal the operating system is running, run uname:
uname -svr
Here the three options of the command, svr, tell Uname to -s print the name of the kernel, -r print the release number, and -v print the version number.
user@yne3:~$ uname -svr
Linux 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017
user@yne3:~$
To read a line of text into a file:
read line
To read a file, run the more command:
more
Here the file is called passwd.
user@yne3:~$ more /etc/passwd
Read the text file.
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin ...etc
To scroll down the document line by line, press enter, return or the space bar.
To go forward to the next page, press f and to go back a page press b. To quit and go to a new command prompt, press q.
To make a copy cp of a file within one directory:
Always use the cp command with the -i option to be sure not to overwrite a file with the same name.
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user/Desktop$ cp -i aclsudo floppyt
cp: overwrite 'floppyt'? n
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user/Desktop$ cp -i aclsudo aclcopy
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user/Desktop$ ls
aclcopy finefriend restorubuntu
aclsudo floppyt sudofloppy
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user/Desktop$
Also use the -i option with the mv move and rm remove commands.
To manage many files, use wildcards in a command. There are three wildcards: the asterisk, question mark and square brackets.
To copy all the files in one directory to another, use an asterisk.
user@yne3:~$ cp ~/Desktop/folder1/* ~/Desktop/directory2/
user@yne3:~$ ls ~/Desktop/directory2/
linuxhow1st
user@yne3:~$
The tilde ~ sign above means home directory.
To copy files from a CD rom disk, type the directory /media/cdrom.
To search for the word "linux" in all files in the Desktop directory:
user@yne3:~$ grep linux ~/Desktop/*
grep: /home/user/Desktop/Allianz: Is a directory
grep: /home/user/Desktop/directory2: Is a directory
grep: /home/user/Desktop/folder1: Is a directory
grep: /home/user/Desktop/fred: Is a directory
/home/user/Desktop/linuxhow1st: ln -s /usr/src/linux-2.4.20 /usr/src/linux
/home/user/Desktop/linuxsudob:linuxhow1st
/home/user/Desktop/linuxsudob: To search for the word "linux" in all files in the Desktop directory:
/home/user/Desktop/linuxsudobt:linuxhow1st
user@yne3:~$
To show every file with a name starting with l on the desktop:
user@yne3:~$ ls ~/Desktop/l*
/home/user/Desktop/linuxhow1st /home/user/Desktop/linuxsudobt
/home/user/Desktop/linuxsudob
user@yne3:~$
To list or show every file on the desktop with a name which starts with l and ends with t:
user@yne3:~$ ls ~/Desktop/l*t
/home/user/Desktop/linuxhow1st /home/user/Desktop/linuxsudobt
user@yne3:~$
To list every file in the Desktop directory which has a z in its name:
user@yne3:~$ ls ~/Desktop/*z
alliance Home insurance quote and PDS & SPDS pack - QS216112856.pdf
allianz2019.png
allianzcoverb.png
allianzcover.png
Home insurance policy and PDS & SPDS welcome pack - 20-S027002-DMP.pdf
user@yne3:~$
The list includes files within a folder called Allianz on the desktop.
The ? question wildcard refers to one character only. To copy all files with the same file name but for a different last character:
user@yne3:~$ cp ~/Desktop/2DO? ~/Desktop/folder1/
user@yne3:~$ ls ~/Desktop/folder1/
2DOk 2DOn linuxhow1st
user@yne3:~$
Square bracket [] wildcards include two or more alternative characters. To list all file names on the desktop which begin with the letter l or g: type ls ~/Desktop/[lg]*
user@yne3:~$ ls ~/Desktop/[lg]*
/home/user/Desktop/grep /home/user/Desktop/linuxsudob
/home/user/Desktop/linuxhow1st /home/user/Desktop/linuxsudobt
user@yne3:~$
To see a list of the last 20 commands used:
history
user@yne3:~$ history 20
149 ls ~/Desktop/l*t
150 ls ~/Desktop/*z
151 ls ~/Desktop/*.pdf
152 cp 2DO? ~/Desktop/ ~/Desktop/folder1/
153 cp ~/Desktop/2DO? ~/Desktop/folder1/
154 ls ~/Desktop/folder1/
155 ls ~/Desktop/[lg]*
156 history
157 history 20 ... etc
user@yne3:~$
To see all the history of commands used:
yne@yne3:~$ history | more
Then press enter key to scroll down to the end of the list and a new command prompt.
To copy the last command or any recently used command to a new command line, press the up arrow key. Press the up and down arrow keys to scroll to the command you want. Once shown on the command line, the old command can be edited if need be then run or executed.
To find a command that works, search this text file for a key word.
To see all commands used before, whether they worked or not:
Gedit a new text file and call it say comhistory. Here the file is saved to the desktop. Run the history command and print > its output to the text file.
$ history > ~/Desktop/comhistory
Search the new text for a key command or other word.
To find the history of a command:
$ history | grep commandname
Grep takes the output piped from history and finds the command.
Do not type plain text passwords on the command line. The root user can view the commands history of all other users in the system.
To delete the history of commands:
$ history -c
To delete just one command. Run history to find the line number of that command. The run history agian with the -d delete option.
$ history -d 2176
Pico or Nano is a text editor. It can be started from the Terminal command line.
To write a message in a new text file and save it to the current directory, use Nano editor:
pete@pete-ID:~$ nano testnote
That open an empty test file in the ./ current directory.
Type a message.
Press enter.
Press ctrl-x
Type y at the save buffer prompt.
At name to write prompt press enter.
pete@pete-ID:~$
Run the list command to see the new filename.
ls
Press enter.
It saves files to the current directory ./ by default.
To save the file, type a file name at the bottom of the screen and press enter.
To use Nano, follow the menus and prompts.
To set a new password for a user:
The username here is george.
user@user-H64C-ED4:~$ sudo passwd george
[sudo] password for user:
Enter new UNIX password:
Type a new password.
Retype new UNIX password:
passwd: password updated successfully
user@user-H64C-ED4:~$
To make an ordinary user a superuser administrator:
user@user-H64C-ED4:~$ sudo usermod -a -G sudo george
user@user-H64C-ED4:~$
Someone who can access the boot loader of a computer system can gain root access to the system, as follows.
The next two ways of doing this have been tested okay using Ubuntu.
To reset a forgotten password of the root administrator for Ubuntu Linux:
Start the computer and hold shift key down or press esc repeatedly while booting with bios data on screen.
Select advanced options if you need to to reach the grub menu.
To reset the password for a single user without having to edit commands, skip to the next way below by scrolling down to +++.
At the Grub boot loader menu, press the down or up arrow key to highlight the kernel you use if it is not already highlighted. Do not press enter.
Press e to edit commands before booting.
Find the line that starts with the word linux. Press the arrow down key to put the cursor on that line.
Add the following line at the end of that command line.
init=/bin/bash
Press CTRL-X or F10 to boot in to single user mode with a command prompt like:
root@(none):/#
Type the following command to mount root (/) file system in read/write mode.
mount -o remount,rw /
Press enter and see the prompt again.
To change the password of your administrative account type the command:
passwd username
That is the name of the account of the administrator or single user. It is usually part of the grub command prompt after @. In single user mode, you can show the list of existing users with this command at the grub prompt:
cat /etc/passwd
The user name is at the start of a line which has in it /home/username:/bin/bash
Choose and note a new password.
As prompted to enter new Unix password, type the new password then again to confirm it.
Password updated successfully.
Type the following command to start Ubuntu with the updated password.
exec /sbin/init
Wait for the Ubuntu login prompt and log in with the new password.
That new password will work also for sudo commands in Terminal.
To reset or update a forgotten root password another way for Ubuntu:
At the GRUB boot loader menu, select advanced options for Ubuntu if need be.
On the grub menu, press arrow keys to select generic rescue mode, the second option, and press enter.
In recovery mode, on the list of recovery options, press an arrow to select root shell, or root drop to root shell prompt, or select netroot drop to root shell prompt with networking. Press enter.
If a prompt says password for maintenance, type the password and enter or press ctrl-d to continue booting.
Wait for a root@username prompt like
root@user:~#
Note the username after root@, which may be a name, perhaps with a number, or with a hyphen and directory, or whatever.
In single user mode, type this command to mount the root (/) file system directory in read/write mode.
mount -o remount,rw /
Do not type a space between the comma and r in ,rw.
or root@username # mount -o remount,rw /mountpoint, where mountpoint is the name of the mount point in the / root directory.
If you see usage instructions, a can't find or another message, retype the command correctly.
Back at the root@user:~# command prompt type the password command:
passwd username
or root@ubuntu:~# passwd username
User name is the name used at the login prompt by the root administrator and the name of his user account directory, it's the user name of a single user, eg /home/username/
The username is the account name of the root or single user as shown on the Ubuntu login prompt. The display name may be different from the account name but both should be shown on the login prompt. In single user mode, you can show the list of existing users with command:
cat /etc/passwd
To change the password of the administrative user, type this command:
passwd username
and press enter.
Choose and note a new password. As prompted, enter the new password twice.
Enter new UNIX password:
Type the new password and press enter.
Retype new UNIX password:
Confirm the password and enter.
passwd: password updated successfully
root@ubuntu:~#
Type this command and press enter to apply changes,
exec /sbin/init
If need be, type exit to return back to the recovery menu.
In the recovery menu, select resume normal boot to start the Ubuntu Linux system, and press enter to continue.
At the grub login prompt, type the same username and log in using the new password.
See a new command line for the user, ending with :~$
username@username:~$
or username@hostname:~$
Type this command and press enter to apply changes,
exec /sbin/init
See and new login prompt:
username login:
Type the username.
Password:
type the new password.
If need be, type this grub command to return to graphic mode:
sudo init 2
Press ctrl-alt-del.
Computer system should boot. Press the restart button of the computer if need be.
At the Ubuntu login prompt, select the username and log in with the new password.
There the password for the user was changed but not the password for the root administrator. You cannot login at the Ubuntu prompt with user root and password blank. Still this single user already had all root administration permissions.
To change the password of the root administrator, follow the instructions above until you reach the line about a password command. At the user :~# prompt type
~# passwd root
Enter new Unix password:
This password should be the same as the root or single user.
Follow the rest of the instructions above.
Grub has password commands to stop people using it but they would make it hard to use grub to recover a broken system. That is why by default there is no grub password.
To backup a system file while it is being edited:
$ cp /directory/filename /directory/filename.bak
To backup the configuration file of the Grub bootloader for example,
$ cp /etc/grub.conf /etc/grub.conf.bak
To set the maximum number of days a user has before he must change his password.
$ sudo chage -M 90 username
To see how many days before the administrator must change his password,
sudo chage -l root
e@yne3:~$ sudo chage -l root
[sudo] password for user:
Last password change : Dec 19, 2018
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
user@yne3:~$
To set the firewall called Uncomplicated Fire Wall, ufw, run these commands:
user@yne3:/$ ufw --help
Usage: ufw COMMAND
Commands:
enable enables the firewall
disable disables the firewall
default ARG set default policy
logging LEVEL set logging to LEVEL
allow ARGS add allow rule
deny ARGS add deny rule
reject ARGS add reject rule
limit ARGS add limit rule
delete RULE|NUM delete RULE
insert NUM RULE insert RULE at NUM
route RULE add route RULE
route delete RULE|NUM delete route RULE
route insert NUM RULE insert route RULE at NUM
reload reload firewall
reset reset firewall
status show firewall status
status numbered show firewall status as numbered list of RULES
status verbose show verbose firewall status
show ARG show firewall report
version display version information
Application profile commands:
app list list application profiles
app info PROFILE show information on PROFILE
app update PROFILE update PROFILE
app default ARG set default application policy
user@yne3:/$
See ufwfirewall.txt
To set up a firewall run the UFW commands below.
To check your current UFW ruleset: -
run sudo ufw status
user@yne3:~$ sudo ufw status
[sudo] password for user:
Status: inactive
user@yne3:~$
To enable iPv6 for UFW if need be, as well as iPv4:
sudo nano /etc/default/ufw
larry@larry-id:~$ sudo nano /etc/default/ufw[sudo] password for larry:
# /etc/default/ufw
# Set to yes to apply rules to support IPv6 (no m$
# accepted). You will need to 'disable' and then $
# the changes to take affect.
IPV6=yes
# Set the ...etc...
Edit this file if need be so that it says IPV6=yes , as above. Follow prompts to close the Nano editor.
That configures UFW to write firewall rules for both ipv4 and ipv6, once the configurations have been enabled as shown below.
To let HTTP traffic on port 80 use your server's public network interface with etho0:
larry@larry-id:~$ sudo ufw allow in on etho0 to any port 80
[sudo] password for larry:
Rules updated
Rules updated (v6)
larry@larry-id:~$
That lets your server receive HTTP requests from the public internet.
To configure your server to allow incoming SSH connections:
larry@larry-id:~$ sudo ufw allow 22
[sudo] password for larry:
Rules updated
Rules updated (v6)
larry@larry-id:~$
SSH connections use port 22.
Os run sudo ufw allow ssh .
To show ssh commands:
user@user-computer-518:~$ ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
user@user-computer-518:~$
To enable the UFW firewall after configuring it:
sudo ufw enable
larry@larry-id:~$ sudo ufw enable
Firewall is active and enabled on system startup
larry@larry-id:~$
To reset UFW firewall rules back to defaults, run these two commands.
sudo ufw default deny incoming
sudo ufw default allow outgoing
That denies all incoming connections and allows all outgoing connections, which may be okay for a personal computer.
To show information about a program:
larry@larry-id:~$ info iptables
Quit (core dumped)
Iptables is an administration tool for IPv4/IPv6 packet filtering and NAT. ... etc ...
To leave the information screen, press ctrl.\
To learn commands for Iptables, run -h for help:
larry@larry-id:~$ iptables -h
iptables v1.6.0
...etc
Usage: iptables -[ACD] chain rule-specification [options]
iptables -I chain [rulenum] rule-specification [options]
iptables -R chain rulenum rule-specification [options]
iptables -D chain rulenum [options]
iptables -[LS] [chain [rulenum]] [options]
iptables -[FZ] [chain] [options]
iptables -[NX] chain
iptables -E old-chain-name new-chain-name
etc ..
--set-counters PKTS BYTES set the counter during insert/append
[!] --version -V print package version.
larry@larry-id:~$
To list all rules:
larry@larry-id:/$ sudo iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
larry@larry-id:i
To list all chains:
larry@larry-id:/$ sudo iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
larry@larry-id:/$
To connect to an ftp server on the internet:
$ ftp serveripaddress
user@user-computer-518:~$ ftp 66.220.9.50
Connected to 66.220.9.50.
220 Welcome to the most popular FTP hosting service! Save on hardware, software, hosting and admin. Share files/folders with read-write permission. Visit http://www.drivehq.com/ftp/;
Name (66.220.9.50:user):
Name (66.220.9.50:user): help
530 user (help) not logged on. The account is inactive or disabled
Login failed.
421 Service not available, remote server has closed connection
ftp> quit
user@user-computer-518:~$
That co;nnected to the default port, port 21. If a different port is used, add the -p option followed by whatever port number is used.
ftp -p 23 serveripaddress
Use the Linux command sftp, secure file transfer protocol, to transfer files on the internet. Only use the ftp command to transfer files within the local area network, as ftp is not secure because it does not encrypt data.
To transfer, upload or download files to or from the internet, run ftp for File Transfer Protocol. Without graphic programs like gFTP or Filezilla, files can be transferred using the command:
ftp hostname.
eg # ftp localhost
user@yne3:~$ ftp localhost
ftp: connect: Connection refused
ftp> quit
user@yne3:~$
Type the ftp name or IP address of the remote host computer and the user name and password for the remote host. Files can be uploaded and downloaded. The program also handles hypertext and shell transfer protocols, HTTP and SSH. Type quit to exit FTP. Run the command man ftp to see the user manual.
e@yne3:~$ man ftp
Press the up and down arrow keys to scroll. Within the manual, type help. Type ftp again to come back to the part about ftp. Type q to exit the manual.
FTP(1) BSD General Commands Manual FTP(1)
NAME
ftp — Internet file transfer program
SYNOPSIS
ftp [-46pinegvd] [host [port]]
pftp [-46inegvd] [host [port]]
DESCRIPTION
Ftp is the user interface to the Internet standard File Transfer Proto‐
col. The program allows a user to transfer files to and from a remote network site.
Options may be specified at the command line, or to the command interpreter.
-4 Use only IPv4 to contact any host.
-6 Use IPv6 only.
-p Use passive mode for data transfers. Allows use of ftp in environments where a firewall prevents connections from the outside world back to the client machine. Requires that the ftp server support the PASV command. This is the default if invoked as pftp.
-i Turns off interactive prompting during multiple file transfers.
Manual page ftp(1) line 1 (press h for help or q to quit)
user@yne3:~$ ftp abracadata.com
ftp: connect to address 52.58.78.16: Connection timed out
Trying 2a05:d014:9da:8c10:306e:3e07:a16f:a552...
ftp: connect: Network is unreachable
Lists of anonymous FTP websites online where login passwords are not needed are at
http://www.ftp-sites.org/
https://www.sftp.net/public-online-sftp-servers
https://www.ftpclientserversites.com/anonymous-ftp-sites-domain-com/
Click the .com suffix for .com sites.
eg abraF01.ftp.abracadata.com FTP server 52.58.78.16
ftp://ftp.activestate.com/
ftp://catcode.com/
ftp://cyberia.cfdrc.com/
ftp-proxy-list.downloads.filetransit.com
To look up which port number an internet web server service uses, use grep.
grep servername /etc/services
Here imaps is the name of the web server.
user@yne3:~$ grep imaps /etc/services
imaps 993/tcp # IMAP over SSL
imaps 993/udp
user@yne3:~$
Here are some other services and their protocols:
DHCP - port 67; DNS - port 53; FTP - ports 20 and 21; HTTP, 80; SMPT - 25; POPv3 - 110; IMAPv4 - 143; SSH - 22; Telnet - 23; NFS - 111; NTP - 123; SNMP - 161 and 162.
Telnet also uses other ports.
user@yne3:~$ grep telnet /etc/services
telnet 23/tcp
rtelnet 107/tcp # Remote Telnet
rtelnet 107/udp
telnets 992/tcp # Telnet over SSL
telnets 992/udp
tfido 60177/tcp # fidonet EMSI over telnet
user@yne3:~$
Information about the network services is in the folder /etc/servcies. CD change to root directory then
ayne@yne3:/etc$ gedit services
The protocal of most of these servicers is either tcp or udp but Datagram Delivery uses ddp.
To configure a network connection automatically from the command line, run dhclient.
$ dhclient networkdevicename
To keep your configuration, save it as a file in /etc/network/interfaces
peter@peter-H89U-ED4:~$ dhclient --help
Internet Systems Consortium DHCP Client 4.3.3
Copyright 2004-2015 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Usage: dhclient [-4|-6] [-SNTPI1dvrxi] [-nw] [-p ] [-D LL|LLT]
[-s server-addr] [-cf config-file]
[-df duid-file] [-lf lease-file]
[-pf pid-file] [--no-pid] [-e VAR=val]
[-sf script-file] [interface]
To configure a netname interface using DHCP, run
dhclient netname
To show a list of SFTP commands in terminal run sftp -help:
user@user-computer-518:~$ sftp -help
usage: sftp [-1246Cpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
[-D sftp_server_path] [-F ssh_config] [-i identity_file]
[-o ssh_option] [-P port] [-R num_requests] [-S program]
[-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host
user@user-computer-518:~$
To check if the OpenSSH server is on the remote system, run this command:
$ ssh localhost
ssh: connect to host localhost port 22: Connection refused [email protected]:~$
SSH uses port 22 by default. OpenSSH needs to be installed.
or
user@user-computer-518:~$ sudo service ssh status
[sudo] password for user:
ssh: unrecognized service
user@user-computer-518:~$
To show ssh commands:
user@user-computer-518:~$ ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
user@user-computer-518:~$
To chat on IRC from a Terminal command line, use Irssi. See ircterminal.txt, www.irssi.org, ircnet.txt.
To install a program:
Here the program is irssi for irc chat.
user@user-U-H:/$ irssi
The program 'irssi' is currently not installed. You can install it by typing:
sudo apt install irssi
user@user-U-H:/$ sudo apt install irssi
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
python-attr python-cairo
python-cffi-backend python-cryptography
... etc
python-zope.interface tor tor-geoipdb
torsocks
Use 'sudo apt autoremove' to remove them.
Suggested packages:
irssi-scripts
The following NEW packages will be installed:
irssi
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 655 kB of archives.
etc ...
Unpacking irssi (0.8.19-1ubuntu1) ...
Processing triggers for doc-base (0.10.7) ...
Setting up irssi (0.8.19-1ubuntu1) ...
user@user-U-H:/$
The install command in Linux copies files and sets file attributes. It is not used for installing packages. For installing packages on to your Linux system you should use apt, apt-get, command or yum command.
To list Deb Debian program packages that are installed:
$ sudo apt-cache pkgnames | grep n
The list would be too long without shortening it. Here we run grep to show only packages with nvidia in their names.
user@user-hostname:~$ sudo apt-cache pkgnames | grep nvidia
[sudo] password for user:
nvidia-346-updates
nvidia-331-dev
nvidia-304-updates-dev
... etc ...
To find packages using a key word, try:
sudo apt-search keyword
To update the list of installed packages after installing a new package:
sudo apt-get upgrade
To show information about a program package:
sudo apt-cache show packagename
user@user-hostname:~$ sudo apt-cache show alliance
Package: alliance
Priority: optional
Section: universe/electronics
Installed-Size: 16647
Maintainer: Ubuntu Developers
... etc ...
To run the IRC program Irssi:
user@user-U-H:/$ irssi
To find out about Irssi commands, at the status prompt type /help. Or /help commandname or /help connect.
Each command at this prompt must start with / .
To scroll Irssi, press pageup or pagedown key.
To leave and quit Irssi, type /leave enter /quit enter.
To connect to a network or server:
[(status)] /connect irc.irssi.org
CNOTICE DEAF=D MONITOR=80 are
supported by this server
... etc
11:26 -!- End of /MOTD command.
11:26 p80drone [drone@p80.dronemon]
requested CTCP VERSION from
user:
11:26 -!- Mode change [+i] for user user
[11:27] [user(+i)] [1:irssi (change with
[(status)]
To join a channel or chatroom:
At irssi prompt type /join #channelname
/join #ircnet
11:44 -!- name
[~name@c200-249-234-193.belr6.nsw.optus.com] has joined #ircnet
11:44 -!- ServerMode/#ircnet [+nt] by
efnet.port80.se
11:44 [Users #ircnet]
11:44 [@username]
This line shows that nobody else is in the chat room other than you.
11:44 -!- Irssi: #ircnet: Total of 1 micks
[1 ops, 0 halfops, 0 voices, 0
normal]
11:44 -!- Channel #ircnet created Mon Jun
24 11:44:40 2019
11:44 -!- Irssi: Join to #ircnet was synced
in 2 secs
See your username and ISP address and
the #ircnet promptline at the bottom of the page.
At the prompt, type a relevant question and press enter. See your question on screen. Wait for an answer.
To quit irssi, type /quit.
To change from one connected chat window to another:
At the Terminal window type the command irssi and press enter.
Irssi status window is window 1.
To connect to a server type /connect servername.net .
You connect to the server still in window 1.
At the status prompt type /join #channelname to connect to a chat channel.
This is still on window number #1.
At the status prompt type /join #channelname
status /join/#test
13:49 -!- name_
[~name@c124-257-178-243.belrs5.snet.com] has joined #test
13:49 [Users #test]
13:49 [ iron] [ name_] [ xpentanx]
13:49 -!- Irssi: #test: Total of 3 micks [0 ops,
See that you are now in window 2, 2:IRCnet/#test.
You can join many chat rooms at once, each in a different window.
To switch between windows in Irssi, use Alt-#, where # is the number between 0 and 9 of the window you want to go to. To go back to the status window, type alt-1 .
To talk to only one other person in a chat room,
type /q for /query with that person's mick name.
/q mickname enter. Type your query then /q to close the window.
To change Irssi settings, go ot the status window with alt-1, type /set change settings if need be, then /save to save settings.
To see all of your configured networks and servers:
at the status prompt, /network list
then /server list .
To see what chat channels are in a network:
at the status prompt type /channel list
Scroll by pressing page-down and page-up keys.
06:51 Channel Network Password
Settings
06:51 #lobby EsperNet
06:51 #freenode Freenode
06:51 #irssi Freenode
06:51 #gamesurge GameSurge
06:51 #irssi IRCnet
06:51 #ircsource IRCSource
06:51 #netfuze NetFuze
06:51 #oftc OFTC
06:51 silc SILC
There are two channels called #irssi, one at IRCnet and the other at Freenode.
To join a chatroom channel first connect to its server by typing this command at the status prompt, choosing whichever server you need.
[(status)] /connect freenode
07:02 -mickServ(mickServ@services.)- This
mickname is registered. Please choose a
different mickname, or identify via
/msg mickServ identify .
07:02 -freenode-connect(frigg@freenode/utility-bot/frigg)- Welcome to freenode. To protect the
network all new connections will be
scanned for vulnerabilities. This will
not harm your computer, and vulnerable
hosts will be notified.
07:02 freenode-connect
[frigg@freenode/utility-bot/frigg]
requested CTCP VERSION from mymick:
07:03 -!- Irssi: Your mick is owned by Unknown
[~jack@unaffiliated/jack]
Now join a channel by typing this command at the status line, typing whichever channel you want.
[(status)] /join #irssi
07:09 -!- mymick
[~jack@c124-257-178-243.belrs5.snet.com] has joined #irssi
07:09 -!- Topic for #irssi: **Latest release**:
1.2.0 | https://irssi.org/ | Tip: irssi
commands are preceded by a / |
http://www.irssi.org/documentation/startup | FP:
7EE6 5E30 82A5 FB06 AC7C 368D 00CC B587
DDBE F0E1 | paste:
http://fpaste.scsys.co.uk/irssi
07:09 -!- Topic set by Nei
[~ailin@unaffiliated/nemui] [Tue Feb 12
08:10:09 2019]
07:09 [Users #irssi]
07:09 [@bI ] [+linear ]
07:09 [@Sigyn ] [+linostar ]
07:09 [+\\Mr_C\\ ] [+linuxthefish ]
07:09 [+__4matter_ ] [+Loutomtin ]
07:09 [+_Cyclone_ ] [+lurkless ]
07:0 ... etc
This channel on Freenode has scores of users listed at 7.14am GMT, with your mickname among them.
07:09 -!- Irssi: #irssi: Total of 477 micks [2
ops, 0 halfops, 450 voices, 25 normal]
07:09 -!- Home page for #irssi:
http://www.irssi.org
07:09 -!- Channel #irssi created Mon Aug 4
07:35:13 2003
07:09 -!- Irssi: Join to #irssi was synced in 2
secs
07:09 -!- mode/#irssi [+v mymick] by bI
07 etc ...
[07:19] [+mymick(+i)] [2:Freenode/#irss [Act: 1]
[#irssi]
That is your chatroom prompt. Type a relevant question and press enter. Your question appears in the chatroom like this.
07:22 <+mymick> Where can I find good xarg
command examples that work?
[07:22] [+mymick(+i)] [2:Freenode/#irss [Act: 1]
[#irssi]
After you have asked something, all the chat of other users shows on screen. Wait for a reply.
07:22 <+mymick> Where can I find good xarg
command examples that work?
07:23 -!- fd0`_ is now known as fd0`
07:23 -!- fd0` [~fd0@46-23-87-234.high5.nu] has
quit [Changing host]
07:23 -!- fd0` [~fd0@nluug/members/fd0] has
joined #irssi
07:23 -!- ServerMode/#irssi [+v fd0`] by
verne.freenode.net
07:23 -!- jude_
[~jude@c-68-83-135-10.hsd1.pa.comcast.net] has
joined #irssi
07:23 -!- mode/#irssi [+v jude_] by bI
07:28 -!- jude_
[~jude@c-68-83-135-10.hsd1.pa.comcast.net] has
quit [Quit: leaving]
07:32 * octocow opens a window
07:32 -!- Mad`Man`Da`Lalta [~dost@197.1.254.43]
has joined #irssi
07:32 <+octocow> disgusting
Among current users here are: Jude, verne, fd0, octocow and mymick.
To join a chatroom:
Here the chatroom is #lobby at Undernet.
[18:30] [jack_(+i)] [1:Undernet (change with ^X)]
[(status)] /join #lobby
18:30 -!- jack_
[~jack@c124-257-178-243.belrs5.snet.com] has joined #lobby
18:30 [Users #lobby]
18:30 [@macsn6] [ realwombat] [ jack_]
18:30 -!- Irssi: #lobby: Total of 3 micks [1 ops, 0
halfops, 0 voices, 2 normal]
18:30 -!- Channel #lobby created Sat Jun 1
06:45:31 2019
18:30 -!- Irssi: Join to #lobby was synced in 1 secs
At the channel prompt #lobby, type a question.
18:37 < jack_> I'm connecting with Irssi. How do I
see the micknames of people in the
chat room?
18:38 -!- wombat [~wombat@189.150.46.136] has
joined #lobby
To exit Terminal after chatting with and /quit quitting Irssi:
jack@jack-U-H:~$ irssi
Please wait, waiting for servers to close connections.
That was your initial command to connect.
jack@jack-U-H:~$ exit
To see your current mickname.
At the status prompt, type
/SET mick or /set mick .
Your mick name and settings are shown here.
06:31 -!- Irssi v0.8.19 - http://www.irssi.org
06:37 [completion]
06:37 completion_micks_lowercase = OFF
06:37 [lookandfeel]
06:37 hilight_mick_matches = ON
06:37 hilight_mick_matches_everywhere = OFF
06:37 query_track_mick_changes = ON
06:37 show_mickmode = ON
06:37 show_mickmode_empty = ON
06:37 show_own_mickchange_once = OFF
06:37 [misc]
06:37 netjoin_max_micks = 10
06:37 netsplit_max_micks = 10
06:37 netsplit_micks_hide_threshold = 15
06:37 [server]
06:37 alternate_mick = mymick
06:37 mick = jack
You have set an alternate mickname.
To set an alternative mick name:First /connect to a server.
At the status prompt type /connect ircnet
Then type /SET alternate_mick othermickname
[(status)] /SET alternate_mick othermick1
Then /mick
09:33 -!- Mode change [+i] for user jack_
09:33 -!- Irssi: Your mick is owned by jack
[eggdrop@jack.nervma.net]
09:34 [server]
09:34 alternate_mick = mick1
09:37 -!- Irssi: Your mickname is jack_
[09:40] [jack_(+i)] [1:IRCnet (change with
[(status)]
To see your real chat name:
/set real_name or /SET real_name
09:45 real_name = jack
[09:46] [jack_(+i)] [1:IRCnet (change with
[(status)]
Later you changed your real name to this -
06:42 real_name = jack3
[06:43] [] [1]
[(status)]
To reset your real name:
[(status)] /SET real_name name3
09:45 real_name = jack
09:50 [server]
09:50 real_name = jack3
[09:52] [jack_(+i)] [1:IRCnet (change with
[(status)]
Then /SET real_name
09:53 real_name = jack3
[09:53] [jack_(+i)] [1:IRCnet (change with
[(status)]
To make a new chat channel:
Alt-1 to go to status prompt.
/join #yourchannel
09:43 -!- user
[~jack@43-596=52-105.lons5.net.com] has joined #ubuntu
Here you named your new channel #ubuntu although it has nothing to do with any official Ubuntu channel.
09:43 -!- ServerMode/#ubuntu [+nt] by
ircsource.baconsvin.org
09:43 [Users #ubuntu]
09:43 [@jack]
09:43 -!- Irssi: #ubuntu: Total of 1 micks [1
ops, 0 halfops, 0 voices, 0 normal]
09:43 -!- Channel #ubuntu created Fri Jun 28
09:43:07 2019
09:43 -!- Irssi: Join to #ubuntu was synced in 2
secs
Anybody else is interested in Ubuntu may join your chatroom channel.
To talk in a chat room:
Type on the prompt line at the bottom of the screen and press enter. See chat like this.
09:00 <@supr> MOAR COFFEE PLZ.
09:01 <@Rveyn> https://i.pinimg.com/originals/47/43/05/474305a1a9319a97998fd52754b3c5a3.jpg
09:17 <+user> That's more coffee than I've drunk
in my life.
09:59 <@yoonix> he sticks his whole face in it
09:59 <@yoonix> ...thats what she said
10:04 <+user> There's a coffee shop on every
corner these days.
[11:17] [+user(+i)] [2:IRCSource/#ircsource(+nt
[#ircsource]
To disconnect from a server, at the status line type
/disconnect and press enter.
To leave a channel and its server without quitting Irssi:
Alt-1
/disconnect
To quit or exit Irssi:
Alt 1
/quit
Then to quit Terminal,
/exit
sendmail - Sendmail moves mail messages from one computer to another. Only use it if you use your Linux system as a mail server.
user@yne3:/$ sendmail
The program 'sendmail' can be found in the following packages:
* exim4-daemon-heavy
* exim4-daemon-light
* postfix
* citadel-mta
* courier-mta
* dma
* esmtp-run
* masqmail
* msmtp-mta
* nullmailer
* opensmtpd
* qmail-run
* sendmail-bin
* ssmtp
To see the program manual:
$ man sendmail
By default, Postfix sendmail(1) reads a message from standard input until EOF or until it reads a line with only a . character, and arranges for delivery.
To list emails sent and to be sent:
sendmail mailq
or postqueue
An * means that message is ready to be sent.
An ! means the message is on hold.
Option -F fullname is for from, the full name of the sender where it is not already in a From field.
NAME The sender full name. This is used only with messages that have no From: message header. See also the -F option above.
=r the return address of the sender where delivery error messages are sent.
To try to deliver all queued mail:
postqueue -q
sendmail -q
To see all Postfix admin commands:
postconf -d
To read more about Postfix, find the postconf readme_directory, and sendmail.txt.
To download and install Mailutils:~ sudo apt-get install mailutils, or
jack@jack-U-H:~$ mail
The program 'mail' is currently not installed. You can install it by typing:
sudo apt install mailutils
jack@jack-U-H:~$ sudo apt install mailutils
[sudo] password for jack:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
python-attr python-cairo python-cffi-backend
etc python-zope.interface tor tor-geoipdb torsocks
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libgsasl7 libkyotocabinet16v5 libmailutils4
libmysqlclient20 libntlm0 mailutils-common
mysql-common postfix
Suggested packages:
mailutils-mh mailutils-doc procmail postfix-mysql
postfix-pgsql postfix-ldap postfix-pcre sasl2-bin
dovecot-common postfix-cdb postfix-doc
The following NEW packages will be installed:
libgsasl7 libkyotocabinet16v5 libmailutils4
libmysqlclient20 libntlm0 mailutils mailutils-common
mysql-common postfix
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,275 kB of archives.
After this operation, 15.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Here press y and enter.
Get:1 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libntlm0 amd64 1.4-7 [14.3 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libgsasl7 amd64 1.8.0-8ubuntu2 [118 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libkyotocabinet16v5 amd64 1.2.76-4.1 [295 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial/universe amd64 mailutils-common all 1:2.99.99-1ubuntu2 [257 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 mysql-common all 5.7.11-0ubuntu6 [16.6 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmysqlclient20 amd64 5.7.11-0ubuntu6 [821 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/universe amd64 libmailutils4 amd64 1:2.99.99-1ubuntu2 [439 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/main amd64 postfix amd64 3.1.0-3 [1,152 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/universe amd64 mailutils amd64 1:2.99.99-1ubuntu2 [162 kB]
Fetched 3,275 kB in 2s (1,257 kB/s)
Preconfiguring packages ...
Selecting previously unselected package libntlm0:amd64.
(Reading database ... 176381 files and directories currently installed.)
Preparing to unpack .../libntlm0_1.4-7_amd64.deb ...
Unpacking libntlm0:amd64 (1.4-7) ...
Selecting previously unselected package libgsasl7.
Preparing to unpack .../libgsasl7_1.8.0-8ubuntu2_amd64.deb ...
Unpacking libgsasl7 (1.8.0-8ubuntu2) ...
Selecting previously unselected package libkyotocabinet16v5:amd64.
Preparing to unpack .../libkyotocabinet16v5_1.2.76-4.1_amd64.deb ...
Unpacking libkyotocabinet16v5:amd64 (1.2.76-4.1) ...
Selecting previously unselected package mailutils-common.
Preparing to unpack .../mailutils-common_1%3a2.99.99-1ubuntu2_all.deb ...
Unpacking mailutils-common (1:2.99.99-1ubuntu2) ...
Selecting previously unselected package mysql-common.
Preparing to unpack .../mysql-common_5.7.11-0ubuntu6_all.deb ...
Unpacking mysql-common (5.7.11-0ubuntu6) ...
Selecting previously unselected package libmysqlclient20:amd64.
Preparing to unpack .../libmysqlclient20_5.7.11-0ubuntu6_amd64.deb ...
Unpacking libmysqlclient20:amd64 (5.7.11-0ubuntu6) ...
Selecting previously unselected package libmailutils4:amd64.
Preparing to unpack .../libmailutils4_1% ... etc
Setting up libmailutils4:amd64 (1:2.99.99-1ubuntu2) ...
At the Postfix popup window use mouse or arrow key to select internet or whater, press the tab to select Ok or esc to try again then press enter.
Setting up postfix (3.1.0-3) ...
Adding group `postfix' (GID 130) ...
Done.
Adding system user `postfix' (UID 122) ...
Adding new user `postfix' (UID 122) with group `postfix' ...
Not creating home directory `/var/spool/postfix'. etc
WARNING: /etc/aliases exists, but does not have a root alias.
Postfix is now set up with a default configuration. If you need to make changes, edit/etc/postfix/main.cf (and others) as needed. To view Postfix configuration values, see postconf(1).
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
Running newaliases
Setting up mailutils (1:2.99.99-1ubuntu2) ...
update-alternatives: using /usr/bin/frm.mailutils to provide /usr/bin/frm (frm) in auto mode
... etc
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
To then update the programs list:
jack@jack-U-H:~$ sudo apt update
[sudo] password for jack:
Ign:1 cdrom://Ubuntu 16.04.2 LTS _Xenial Xerus_ - Release amd64 (20170215.2) xenial InRelease
Hit:2 cdrom://Ubuntu 16.04.2 LTS _Xenial Xerus_ - Release amd64 (20170215.2) xenial Release
Hit:4 http://archive.canonical.com/ubuntu xenial InRelease
Hit:5 http://archive.ubuntu.com/ubuntu xenial InRelease
Hit:6 http://ppa.launchpad.net/videolan/stable-daily/ubuntu xenial InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
jack@jack-U-H:~$
To check that Postfix has been installed along with Mailutils:
jack@jack-U-H:~$ postfix
postfix: error: to submit mail, use the Postfix sendmail command
postfix: fatal: the postfix command is reserved for the superuser
jack@jack-U-H:~$
A mail client is a program that sends and gets emails. A default mail server like Sendmail usually comes installed with Linux. A mail transport agent MTA helps send, receive and store emails using smtp, pop3 and imap protocols.
To send emails outside the local system, setup an SMTP server for the mail and mailx command. Mailx is called mail when it is installed.
To download and read emails off line, choose Pop3, not IMAP4 or webmail.
To send an email text message using the Mailx program which comes with Mailutils:
At the Terminal prompt $ type mail -s "Subject of email" recipinet@servname.com
The -s option means subject. A -t means the recipient you are sending email to. An -r means the return email adress other than the default.
In mail window, type the message. Press enter for new lines.
Press enter . full stop enter to end the message so that the last line shows only a full stop.
Then Ctrl-D to deliver the message.
See EOT as mailx delivers the email to its recipient.
jack@jack-U-H:~$ mail -s "Test email via mailx" -t george@gmail.com -r helen@optus.com
Cc:
This is Test 4.
.
jack@jack-U-H:~$
jack@jack-U-H:~$ mail -s "Test email via mailx" -t Malb@protonmail.com
Cc:
This message is to test an email typed at the Terminal.
jack@jack-U-H:~$
That message failed to reach Protonmail.
eg $ mail -s "This is the subject" someone@example.com
Hi someone
How are you. I am fine.
Bye
EOT
mail -s "Test email via mailx" -t george@gmail.com -r helen@opus.com
sendmail - To send an email message:
username@username-ID:~$ sendmail walb@protonmail.com
Type an email message here.
End the message on a new line by typing enter fullstop enter.
.
username@username-ID:~$
Sendmail sends the message when you end it with enter.enter then shows a new command prompt.
To abort writing an email message:
Press ESC key or Ctrl\ to quit and go back to a command prompt.
To see the user's name and a list of emails in the user's directory:
$ mailx
jack@jack-U-H:~$ mailx
"/var/mail/jack": 3 messages 3 new
>N 1 Mail Delivery Syst Tue Jun 25 17:54
N 2 Mail Delivery Syst Tue Jun 25 18:06
N 3 Mail Delivery Syst Tue Jun 25 18:08
?
Press ESC key to quit.
To take the message from a file:
$ mail -s "This is Subject" someone@example.com < /path/to/file
To send the email to many recipients, separated the email addresses by commas:
$ echo "This is message body" | mail -s "This is Subject" someone@example.com,someone2@example.com
There a pipe was used.
The "-c" and "-b" options can be used to add CC and BCC addresses respectively.
$ echo "This is message body" | mail -s "This is Subject" -c ccuser@example.com someone@example.com
5. Specify From name and address
To specify a "FROM" name and address, use the "-r" return option. The name should be followed by the address wrapped in "<>".
$ echo "This is message body" | mail -s "This is Subject" -r "Harry" someone@example.com
6. Specify "Reply-To" address
The reply to address is set with the internal option variable "replyto" using the "-S" option.
# replyto email
$ echo "This is message" | mail -s "Testing replyto" -S replyto="mark@gmail.com" someone@example.com
# replyto email with a name
$ echo "This is message" | mail -s "Testing replyto" -S replyto="Mark" someone@example.com
7. Attachments
Attachments can be added with the "-a" option.
$ echo "This is message body" | mail -s "This is Subject" -r "Harry" -a /path/to/file someone@example.com
To show statistics about network connections, run netstat or ss.
To check that an smtp server (mta) is running locally:
$ netstat
qq.qq.jack@jack-U-H:~$ sudo netstat -lnp | more
[sudo] password for jack:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address
Foreign Address State PID/Prog
ram name
tcp 0 0 127.0.1.1:53
... etc Press enter to scroll.
G 23090 1734/master private/i
fmail
unix 2 [ ACC ] STREAM LISTENIN
G 23093 1734/master private/b
smtp
unix 2 [ ACC ] STREAM LISTENIN
G 23096 1734/master private/s
calemail-backend
G 23099 1734/master private/m
ailman
ets ...
Mailx command can also read emails from remote IMAP servers.
To show the mail configuration file summary:
$ mail --config-help
jack@jack-U-H:~$ mail --config-help
# Configuration file structure for mail utility.
# For use in global configuration file (/etc/mailutils.rc), enclose it in
# `program mail { ... };
# For more information, use `info mail'.
tls {
# Enable TLS encryption.
enable ;
# Specify SSL certificate file.
...etc
include ;
jack@jack-U-H:~$
To show more information about the mail program:
$ info mail
To show a list of mail.log files, change to the /var/log/ directory and run this list command:
username@username-ID:~$ cd /var/log/ ; ls
alternatives.log boot.log hp syslog
alternatives.log.1 bootstrap.log installer etc ...
apport.log.6.gz dpkg.log.2.gz mail.err unattended-upgrades
apport.log.7.gz dpkg.log.3.gz mail.err.1 upstart
apt dpkg.log.4.gz mail.log wtmp
auth.log dpkg.log.5.gz mail.log.1 wtmp.1
auth.log.1 faillog mail.log.2.gz Xorg.0.log
auth.log.2.gz fontconfig.log mail.log.3.gz Xorg.0.log.old
auth.log.3.gz fsck mail.log.4.gz
auth.log.4.gz gpu-manager.log speech-dispatcher
username@username-ID:/var/log$
Maillog holds a history of send and receive email addresses, including spammers.
To show a history of email activity:
:/var/log$ gedit mail.log.1
username@username-ID:/var/log$
Aug 2 08:13:50 username-hostname postfix[3520]: Postfix is running with backwards-compatible default settings
... etc
Aug 2 08:13:58 username-hostname postfix[3658]: Postfix is running with backwards-compatible default settings ... etc ...
To email somebody right after executing a command, add this command, separated by a semicolon ; :
; mail -s "Just finished running that long command." helen@opus.com
Here Helen is to receive the message.
Commands written on one line and separated by semicolons ; are called sequential commands and are executed one after the other.
To quit a program and return to the command prompt in Terminal, press the Ctrl key and backslash key together,
ctrl-\ .
Here the program grep s looking for the game solitaire.
user@user-U-H:~/Desktop/testfold$ grep sol
^\Quit (core dumped)
user@user-U-H:~/Desktop/testfold$
at - This command can be used to tell Linux to run or execute one or more commands later in the day.
cron - A cron job command tells Linux to run some user commands at regular intervals, daily, weekly, monthly, whatever. Cron can run sh shell commands which lead from one command to the next alternative command. At and cron can send an email to the user with output to tell about results of a cron job.
NFS means Network File System, sharing files with users of other computers on a network.
date - shows the time and today's date
cal - shows a calender for this month
pwd - prints to screen the current working directory
The words foo and bar are slang for names, functions and other variables in command lines. Example:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
Zip is cross platform and does a better job than Tar.
tar - Tar program can be used to backup files to a separate hard drive, usb drive or SCSI tape. Optionally it can compress the backup archive. Files and directories can be added to a .tar file to update it but cannot be added to a compress tar file, .targz. The tar command goes:
tar options destination source.
To backup all the files on the computer desktop into a tar file: -
Make a backup directory, with any name, to work in.
barry@barry-G44B-OI2:~$ mkdir ~/Backups
barry@barry-G44B-OI2:~$ ls
Backups examples.desktop Public
Desktop Music Scripts
Documents Pictures Templates
Downloads Programs Videos
Change cd to the backup directory.
barry@barry-G44B-OI2:~$ cd ~/Backups/
barry@barry-G44B-OI2:~/Backups$ ls
Backup the files.
Here the -c option says to create a new archive, and the -f option says to use it as an archive file.
barry@barry-G44B-OI2:~/Backups$ tar -cf deskback.tar ~/Desktop/*
tar: Removing leading `/' from member names
barry@barry-G44B-OI2:~/Backups$ ls
deskback.tar
barry@barry-G44B-OI2:~/Backups$
To compress a tar archive, run tar with an option -z, -Z or -a as shown in tar --usage.
To type a list of all the files in the new tar archive:
barry@barry-G44B-OI2:~/Backups$ tar -tf deskback.tar
home/barry/Desktop/2DO
home/barry/Desktop/backscript
home/barry/Desktop/testtar ... etc ...
home/barry/Desktop/unziphow
home/barry/Desktop/zipsudo
barry@barry-G44B-OI2:~/Backups$
To untar an archive, that is extract or get all the files out of a tar archive:
barry@barry-G44B-OI2:~/Backups$ tar -xf deskback.tar
tar: home/barry/Desktop/unziphow: time stamp 2019-08-06 22:35:14 is 17267.803266489 s in the future
barry@barry-G44B-OI2:~/Backups$ ls
deskback.tar home
barry@barry-G44B-OI2:~/Backups$
Tar has put a folder called home in the backups directory.
That tar command can also extract files with extensions .tar.gz and .tar.bz2.
To list the files in the new backup directory:
barry@barry-G44B-OI2:~/Backups$ ls ./home/barry
barry@barry-G44B-OI2:~/Backups$ ls ./home/*
Desktop
barry@barry-G44B-OI2:~/Backups$ ls ./home/*/*/
backscript testtar ... etc
linuxsudob9 unziphow
restorubuntu zipsudo
barry@barry-G44B-OI2:~/Backups$
They are the files unzipped.
A zip is a file, not a folder. When you zip a folder full of files, it becomes a zip file, no longer a folder. You cannot copy and paste or move files into a zip or any other kind of file. You have to zip them in. Unlike ordinary files, zip files hold other files inside, zipped files. You can zip a folder full of files into a zip file which is already there.
To extract files from a tarfile in a directory other than the local one:
tar -xf tarfilename.tar -C /directoryname/
The big -C option tells Tar to change to the directory typed here.
To extract one file from a tar archive:
tar -xf atchivename.tar directory/filename
Change to the backup directory and list the files in it.
barry@barry-H87E-OA5:~$ cd ~/Backups/
barry@barry-H87E-OA5:~/Backups$ ls
deskback.tar home
Here there is the archive and a folder of extracted files. List the files in the folder.
barry@barry-H87E-OA5:~/Backups$ ls ./home
barry
barry@barry-H87E-OA5:~/Backups$ ls ./home/barry/Desktop/
2DO linuxsudob9 start-tor-browser.desktop zipsudo
backscript restorubuntu unziphow
A file called testtar to be extracted is missing from the folder.
Check that the missing file is in the archive.
barry@barry-H87E-OA5:~/Backups$ tar -tf deskback.tar
home/barry/Desktop/2DO
home/barry/Desktop/backscript
home/barry/Desktop/linuxsudob9
home/barry/Desktop/restorubuntu
home/barry/Desktop/testtar
home/barry/Desktop/unziphow
home/barry/Desktop/zipsudo
Copy the full name of the file home/barry/Desktop/testtar onto the clipboard and paste it into the next command. This command will extract the file into the same folder called home.
barry@barry-H87E-OA5:~/Backups$ sudo tar -xf deskback.tar home/barry/Desktop/testtar
barry@barry-H87E-OA5:~/Backups$ ls ./home/barry/Desktop/2DO linuxsudob9 unziphow
backscript restorubuntu testtar zipsudo
barry@barry-H87E-OA5:~/Backups$
If tar shows a failure status message and does not extract the file, the user may have been denied reader permission. Try typing sudo before the tar command. Try changing user permissions for the backup folder and the files in it so that other users can read and write to them.
To read or edit an extracted file:
List the folder holding extracted files. Cut from the list the full name of the file to be read. Paste the full name after the edit command.
barry@barry-H87E-OA5:~/Backups$ gedit home/barry/Desktop/testtar
barry@barry-H87E-OA5:~/Backups$
Read the file in gedit or whichever editor is used.
Usage: tar [OPTION...] [FILE]...
GNU 'tar' saves many files together into a single tape or disk archive, and can restore individual files from the archive. etc ...
To test whether a tar file is alright, type a big -W option:
tar -tvfW archivename.tar
The -t option is to type a list of the files in the archive and the -v option is to type notes about the test results.
barry@barry-G44B-OI2:~/Backups$ tar -tvfW deskback.tar
tar: W: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
barry@barry-G44B-OI2:~/Backups$
To backup a directory of files using Tar:
$ tar -cf ~/Backup/deskback.tar ~/Desktop/*
The -cf options tell Tar to create a tar file, fill it with all the files on the computer's desktop and save it into a directory called Backup. The arguments of the -f option are ~/Backup/deskback.tar ~/Desktop/*
barry@barry-G44B-OI2:~$ mkdir /home/barry/Backup
barry@barry-G44B-OI2:~$ ls
Backup examples.desktop Scripts
Music Templates
Desktop Pictures Videos
Documents Programs
Downloads Public
barry@barry-G44B-OI2:~$ tar -cf ~/Backup/deskback.tar ~/Desktop/*
tar: Removing leading `/' from member names
barry@barry-G44B-OI2:~$ ls ~/Backup
deskback.tar
barry@barry-G44B-OI2:~$
To type a list all the files in a Tar archive:
tar -tf archivename.tar
Here the create command is repeated and the c changed to t.
$ tar -tf ~/Backup/deskback.tar
barry@barry-G44B-OI2:~$ tar -tf ~/Backup/deskback.tar
home/barry/Desktop/2DO
home/barry/Desktop/backscript
... etc
home/barry/Desktop/testtar
home/barry/Desktop/unziphow
barry@barry-G44B-OI2:~$
To extract or get all the files out of a tar archive, use the -x option with an argument showing where the archive is. Or change to the backup directory and extract the files into that same directory.
barry@barry-G44B-OI2:~$ cd ./Backup
barry@barry-G44B-OI2:~/Backup$ ls
deskback.tar
barry@barry-G44B-OI2:~/Backup$ tar -xf deskback.tar
This command can also extract .tar.gz and .tar.bz2 files.
To type a list of files in a tar archive in a different directory, type the directory name before the tar file name.
barry@barry-H87E-OA5:~$ tar -tf ~/Backups/deskback.tar
To list the files in a tar archive with verbose information:
$ tar -tvf archivename.tar
The v is for a verbose, longer, list.
barry@barry-G44B-OI2:~/Backup$ tar -tvf deskback.tar
-rw-rw-r-- barry/barry 221 2019-08-03 14:49 home/barry/Desktop/2DO
-rw-rw-r-- barry/barry 625 2019-08-05 09:47 home/barry/Desktop/backscript
-rw-rw-r-- barry/barry 375925 2019-08-06 14:33 home/barry/Desktop/linuxsudob9 ... etc ...
-rw-rw-r-- barry/barry 16267 2019-08-04 15:39 home/barry/Desktop/testtar
-rw-r--r-- barry/barry 4843 2019-08-06 22:35 home/barry/Desktop/unziphow
To extract or unzip one file from a tar archive:
tar -xf archivename.tar filename.txt
To extract the files from a tar archive in a different directory from the current one:
barry@barry-H87E-OA5:~$ tar -xf ~/Backups/deskback.tar
barry@barry-H87E-OA5:~$ ls ~/Backups/
deskback.tar home
barry@barry-H87E-OA5:~$
The files are in the home directory.
To read a text file from a tared archive:
gedit /directoryname/filename
barry@barry-G44B-OI2:~$ gedit /home/barry/Backupdesk/home/barry/Desktop/mirrors
Gedit opens a file called mirrors in a directory called /Backupdesk.
... parsed the official mirror lists and tried to connect all the http mirrors on https instead. Here is the resulting ... etc.
To change to the root directory, type cd /
To go to the home directory, type cd
To change to home directory, type, cd ~
To toggle between two directories, type -
yne@yne3:~$ cd /
user@yne3:/$ cd
user@yne3:~$ cd /
user@yne3:/$ cd ~
user@yne3:~$ cd -
/
user@yne3:/$ cd -
/home/user
user@yne3:~$
Never delete files from a tar archive stored on tape because that may corrupt the archive.
To add files to an existing .tar archive to update it, run the following commands.
$ tar -rvf archivename.tar filename
The options tell Tar to -r append or add files to the end of the -f archive file then -v verbosely list them.
Here we cd change to a hidden directory called .locker which holds a hidden tar archive called .locked.tar.
larry@larry-id:~/.locker$ ls -a
. .. .locked.tar testhide testtar
larry@larry-id:~/.locker$
The directory also holds two test files.
larry@larry-id:~/.locker$ tar -rfv .locked.tar ./test*
larry@larry-id:~/.locker$
That added test files in the directory into the tar file.
larry@larry-id:~/.locker$ tar -tvf .locked.tar
-rw-rw-r-- larry/larry 52 2019-08-30 10:58 testhide
-rw-rw-r-- larry/larry 61 2019-08-30 10:31 testtar
larry@larry-id:~/.locker$
larry@larry-id:~/.locker$ ls -a
. .. .locked.tar testhide testtar
Copies of test files need to be deleted from the directory.
To navigate to, find or open and list the files with their user permissions on a second hard disk drive:
Ubuntu mounts other hard drives at /media/. Start by ls listing /media/ then add directories until you reach the one wanted.
Here the files are in a hidden directory called .locker. The long number is the name of the second hard drive.
user@user-ID:/$ ls -al /media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/.locker/
total 1581268
drwx------ 2 user user 4096 Sep 14 13:37 .
drwxr-xr-x 26 user user 4096 Sep 8 12:50 ..
-rw-rw-r-- 1 user user 809566824 Aug 26 14:36 locked.zip
-rw-rw-r-- 1 user user 49075362 Aug 26 14:39 pic9024e.zip
-rw------- 1 user user 760549263 Aug 7 17:23 de1438e.zip
-rw-rw-r-- 1 user user 1078 Sep 14 13:37 zipping
user@user-ID:/$
Only root has permission to open one of the encrypted zip files.
user@user-ID:/$ ls -al /media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/.locker/
total 1581268
drwx------ 2 user user 4096 Sep 14 13:37 .
drwxr-xr-x 26 user user 4096 Sep 8 12:50 ..
-rw-rw-r-- 1 user user 809566824 Aug 26 14:36 locked.zip
-rw-rw-r-- 1 user user 49075362 Aug 26 14:39 pic9024e.zip
-rw------- 1 user user 760549263 Aug 7 17:23 de1438e.zip
-rw-rw-r-- 1 user user 1078 Sep 14 13:37 zipping
user@user-ID:/$
To copy files from a hidden locker directory to a floppy disk:
username@username-ID:~$ mount /dev/fd0
username@username-ID:~$ sudo cp ~/.locker/encrypt/* /media/floppy0/
username@username-ID:~$ ls /media/floppy0
gnupg gpgremove pgphowcut sudogpg
gpghow keyring pgpkey
username@username-ID:~$
Seven files copied.
username@username-ID:~$ umount /dev/fd0
username@username-ID:~$
To copy cp a file from a second hard drive to the first hard drive on the same computer:
user@user-ID:/$ cp /media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/.locker/de1438e.zip ~/Desktop/
user@user-ID:/$ ls ~/Desktop/
fdformatlive fstabmount de1438e.zip
user@user-ID:/$
To copy files from a directory on a second hard drive to a floppy disk:
user@user-ID:/media/floppy0$ cp /media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Pictures/* ./
user@user-ID:/media/floppy0$ ls
92d7f0f2.jpg sanfran.jpg
b84874b9.jpg
user@user-ID:/media/floppy0$
There were three files in all * in the directory. They were copied to the current directory ./ .
To copy a zip file from a second hard drive to a floppy disk:
This zip file was too big to fit on the floppy.
user@user-ID:/$ cp /media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/.locker/de1438e.zip /media/floppy/
cp: error writing '/media/floppy/de1438e.zip': No space left on device
user@user-ID:/$
To -a append or add a directory of files into the tar archive:
tar -rvf archivename.tar directoryname/
Here the directory to be archived is called backup3 and it is on a USB memory stick called redusb.
First copy the directory into the directory which holds the tar archive file.
larry@larry-id:~/.locker$ cp -r /media/larry/red8gbusb/backup3/ ./backup3/
larry@larry-id:~/.locker$ ls -a
. .. backup3 .locked.tar
Then add it to the archive.
larry@larry-id:~/.locker$ tar -rfv .locked.tar ./backup3/
larry@larry-id:~/.locker$
To check that the files have been added to the archive:
larry@larry-id:~/.locker$ tar -tvf .locked.tar
-rw-rw-r-- larry/larry 52 2019-08-30 10:58 testhide
-rw-rw-r-- larry/larry 61 2019-08-30 10:31 testtar
drwxr-xr-x larry/larry 0 2019-08-30 13:53 ./backup3/
-rw-r--r-- larry/larry 318837 2019-08-30 13:53 ./backup3/bill419b.png
... etc ...
To hide the index of a zip archive, move the archive into a directory then zip the directory. That puts one archive into another archive. When the first archive is opened for extraction, its index lists only one file, the second archive. Any user needs the zip password to extract the first archive and show the index of all the files in the second archive, then a password again to access those files.
A locker is good for a small zip archive. Large archives and archives within archives become too slow to extract files from and to update.
To quit a password prompt without knowing the password:
ctrl-\
control=backslash.
To find and translate, delete or replace characters throughout a file, run the tr command.
tr "characters to be translated" "characters they are to be translated into" < name of file-to-translate
To translate a text message into a code:
Here keep the number of letters equal to the number of numbers.
user@user-H64C-ED4:~$ echo | tr "abefikosu." "0593214876" < ~/Desktop/memotest
M9m4: 5873
Th28 28 0 t9xt m9880g9 t4 t98t 0 tr0n8l0t24n 2nt4 82mpl9 c4d96 S4m9 l9tt9r8 0nd p7nct70t24n 0r9 tr0n8l0t9d 2nt4 n7m59r86
Tr has translated or encrypted the memo into code, by changing letters to numbers, and echo has displayed the code.
To decrypt or translate the code back into the original message:
Copy and paste the output code into a text file, this one being called codetest. Then run this command being sure that the < character is the right way round -
user@user-H64C-ED4:~$ echo | tr "0593214876" "abefikosu." < ~/Desktop/codetest
Memo: bsuf
This is a text message to test a translation into simple code. Some letters and punctuation are translated into numbers.
user@user-H64C-ED4:~$
The code is translated. Although the memo number is changed to letters, it can still be found on the code.
It helps to change to the directory holding the files you are working with.
user@user-H64C-ED4:~$ cd ~/Desktop
user@user-H64C-ED4:~/Desktop$ tr "abefikosu." "0593214876" < memotest >> codetest
user@user-H64C-ED4:~/Desktop$ cat codetest
M9m4: 5873
Th28 28 0 t9xt m9880g9 t4 t98t 0 tr0n8l0t24n 2nt4 82mpl9 c4d96 S4m9 l9tt9r8 0nd p7nct70t24n 0r9 tr0n8l0t9d 2nt4 n7m59r86
M9m4: 5873
Th28 28 0 t9xt m9880g9 t4 t98t 0 tr0n8l0t24n 2nt4 82mpl9 c4d96 S4m9 l9tt9r8 0nd p7nct70t24n 0r9 tr0n8l0t9d 2nt4 n7m59r86
user@user-H64C-ED4:~/Desktop$
Because the tr command was followed by two >> signs instead of one, the code copied from screen was added after that which was already in the file instead of writing over it.
To test whether the Tar program is installed and working, type the tar command without any options.
user@yne3:/$ tar
tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options
Try 'tar --help' or 'tar --usage' for more information.
user@yne3:/$
This shows that Tar is working.
To backup files,
$ tar options destination source
Options for tar do not begin with a hyphen - .
tar cvf /home/user/backuptest /home/user/Desktop
This command does not have a z option to compress the files being backed up. The /backuptest destination directory was made before using Tar.
user@user-K-ED4:~$ tar cvf /home/user/backuptest/deskback /home/user/Desktop/*
tar: Removing leading `/' from member names
/home/user/Desktop/1streadcd
/home/user/Desktop/2DO
/home/user/Desktop/2DOn
/home/user/Desktop/Allianz/
/ho ... etc
That command backed up every file in the Desktop directory and in the subdirectories of /Desktop.
Tar for Ubuntu16 is not compatible with Tar for Ubuntu 10. So Tar is risky and inefficient, like some other backup programs. Zip program archives and compresses files, like Tar does. But Zip is backwardly compatible and works cross-platform with Linux and Windows, Winzip and Pkzip. Zip can also encrypt files and protect archives with passwords. Zip encryption is weak so private and personal files can be encrypted with SSL instead, Openssl, for strong encryption.
To see what files are in a tar archive:
tar tf /destination/archivefile
tar tf ~/backuptest/deskback
user@user-K-ED4:~$ tar tf ~/backuptest/deskback | more
Press the enter key to scroll down.
... home/user/Desktop/removed18
home/user/Desktop/sb26519.odt
home/user/Desktop/sb26519.png
home/user/Desktop/start-tor-browser.desktop
home/user/Desktop/sum678.sh
home/user/Desktop/ufwfirewall
user@user-K-ED4:~$
To extract the files from the backup archive:
Do not run the tar x extract command before changing to the right directory or the computer will hang.
Change to the directory which contains the archive file.
cd ~/backuptest/
user@user-K-ED4:~$ cd ~/backuptest/
user@user-K-ED4:~/backuptest$ ls
deskback
user@user-K-ED4:~/backuptest$
This command restores the backed up files to the current directory.
tar xvf /destinationdirectory/backupfilename
$ tar xvf ~/backuptest/deskback
user@user-K-ED4:~/backuptest$ tar xvf ~/backuptest/deskback
home/user/Desktop/1streadcd
home/user/Desktop/2DO
home/user/Desktop/2DOn
home/user/Desktop/Allianz/ ... etc.
home/user/Desktop/sum678.sh
home/user/Desktop/ufwfirewall
user@user-K-ED4:~/backuptest$
user@user-K-ED4:~/backuptest$ ls
deskback home
user@user-K-ED4:~/backuptest/home/user/Desktop$ ls
1streadcd grep opus$90overcharge.odg start-tor-browser.desktop
2DO linuxhow1st opus$90overcharge.png sum678.sh
2DOn linuxsudob removed18 ufwfirewall
Allia mirrorfail sb26519.odt
mirrors sb26519.png
user@user-K-ED4:~/backuptest/home/user/Desktop$
Open a recovered text file.
user@user-X-ED4:~/backuptest/home/user/Desktop$ gedit ~/backuptest/home/user/Desktop/2DOn
The text file opens so the Tar backup test worked.
The echo command displays argument arg information requested.
To find what program is installed as the interpreter of shell script:
$ echo $SHELL
user@yne3:/$ echo $SHELL
/bin/bash
user@yne3:/$
So Bash is the shell command interpreter and it's in the binary directory with other programs.
The command sign #! is called a shebang. Scripts should start with this line as a shell interpreter definition:
#! /bin/bash
A shell script file is made executable by the chmod command:
chmod +x filename
Filenames of shell scripts end with the extension .sh
The same commands which run manually one at a time in Bash using Terminal can be typed into a Bash shell script and run automatically one after the other from top to bottom. To write a shell script, open gedit text editor and start a new file with an .sh extension.
$ gedit ~/Desktop/filename.sh
Or it can be in any other directory, /directoryname/filename.sh.
Type the first line of the script as #! /bin/bash
type in commands like echo "Hello"
Save the text file, close it and exit the editor.
Make the script executable with chmod command
$ chmod +x ~/Desktop/filename.sh
Change directory to where the shell file is saved, cd ~/Desktop.
Execute the shell with the command:
$ ./filename.sh
Chmod changes the permissions mode of a file.
To make a new script in its current directory executable by typing only its name.sh:
chmod +x ./scriptname.sh
To stop everybody from running a program:
Here it is the game solitaire.
user@user-U-H:~/Desktop/testfold$ sudo chmod a=--- /usr/games/sol
[sudo] password for user:
user@user-U-H:~/Desktop/testfold$ ls -l /usr/games/sol
---------- 1 root root 281848 Nov 12 2015 /usr/games/sol
user@user-U-H:~/Desktop/testfold$
To let everybody play the game again:
user@user-U-H:~/Desktop/testfold$ sudo chmod a=rwx /usr/games/sol
To run the graphic game program:
user@user-U-H:~/Desktop/testfold$ sol
To revoke take back from all users permission to execute a file:
This file is called memotest.
user@user-U-H:~/Desktop/testfold$ ls -l memotest
-rw-rw-r-- 1 user user 133 Jun 17 08:47 memotest
user@user-U-H:~/Desktop/testfold$ sudo chmod a-rwx memotest
user@user-U-H:~/Desktop/testfold$ ls -l memotest
---------- 1 user user 133 Jun 17 08:47 memotest
user@user-U-H:~/Desktop/testfold$
To give everybody permission to read, write or execute the file:
Change the minus - to a plus +.
user@user-U-H:~/Desktop/testfold$ sudo chmod a+rwx memotest
user@user-U-H:~/Desktop/testfold$ ls -l memotest
-rwxrwxrwx 1 user user 133 Jun 17 08:47 memotest
user@user-U-H:~/Desktop/testfold$
To store scripts written by the user, make a subdirectory called ~/Scripts, that is in the /home/user/directory, and save or copy the user's scripts into it. Give each script a name of one word only with a .sh extension to readily show that it is a shell script.
user@user-U-H:/$ ls ~/
Documents examples.desktop Pictures Public Templates
Desktop Downloads Music Programs Scripts Videos
user@user-U-H:/$
To let only the owner of a script edit or modify it and anybody else to execute it, run octal code 755:
# chmod 755 scriptname.sh
or $chmod rwxr-xr-x ./scriptname.sh
user@user-H64C-ED4:~/Scripts$ chmod 755 ./router.sh
user@user-H64C-ED4:~/Scripts$ ./router.sh
Checking to see whether router route -n | grep UG | tr -s "" | cut -f 2 -d "" is working...
ping: unknown host route
user@user-H64C-ED4:~/Scripts$
To deny access to a shell for anybody but its owner, use code 700 or:
user@user-U-H:~/Scripts$ ls -l propert.sh
-rwxrwxr-x 1 user user 302 Jun 22 17:57 propert.sh
user@user-U-H:~/Scripts$ sudo chmod u+rwx,g-rwx,o-rwx ./propert.sh
user@user-U-H:~/Scripts$ ls -l propert.sh
-rwx------ 1 user user 302 Jun 22 17:57 propert.sh
user@user-U-H:~/Scripts$
User permission options:
chmod a+x or ug=rw or o-rwx or g-w,o-rw
Plus + means give permission and minus - means take permission away.
a - all users
u - user who owns the file
g - users in same group as owner
o - other users
If no letter says which users, the default is a for everybody
= - an equal sign goes between the user and his permissions, like this u=rwx.
r - read w - write x - execute
A permission string goes like this:
file type, owner, group, others -
txt, rwx, rwx, rwx.
chmod u=rwx,g=rx,o=r myfile
sudo chmod permissionstring filename
To show what permissions are set for a file, use List with the -l long option:
ls -l file.txt
Here the file called testlistk is in the current directory.
user@user-U-H:~/Desktop/testfold$ ls -l testlistk
-rwxrwxrwx 1 user user 55 Jun 5 14:40 testlistk
user@user-U-H:~/Desktop/testfold$
To change the permissions mode of the file so that only the owner can read, write to or exit it:
user@user-U-H:~/Desktop/testfold$ sudo chmod u=rwx,g=---,o=--- ./testlistk
[sudo] password for user:
user@user-U-H:~/Desktop/testfold$ ls -l testlistk
-rwx------ 1 user user 55 Jun 5 14:40 testlistk
user@user-U-H:~/Desktop/testfold$
To deny permission, replace an r, w or x with a hyphen like this:
rwxr-xr--
There only the owner has permission to write to the file. Only the owner and members of his group can execute the file.
To stop anybody who is not in the user group from accessing a file:
This file is called listtest.
user@user-U-H:~/Desktop/testfold$ sudo chmod u=rw-,g=rw-,o=--- ./listtest
user@user-U-H:~/Desktop/testfold$ ls -l listtest
-rw-rw---- 1 user user 101 Jun 19 15:12 listtest
user@user-U-H:~/Desktop/testfold$
Default permissions for a file are, unless the root user has changed the default:
The owner of the file and the group he is in can read and write to the file but other users can only read the file. Only the root user has permission by default to read or write to an executable file.
You can use expressions like if, while, for, case and until in shell commands. Such commands can control the order in which other shell commands in the script are executed.
Write scripts one command line at a time. First write a command then run it in terminal. When the command works in Terminal, copy and paste it as the next line of script.
Linux commands do not include the $ sign but are what is typed after the $ which ends a command prompt.
To write a shell script: -
Begin by typing the first shell command line. This command tells which binary directory the bash program is in.
#! /bin/bash
Give the new shell script a name. Call this one "hello", with 3 brackets.
hello() {
Type shell command such as
echo -n "Hello, "
echo $1 $2
}
See how the body of the shell function above is enclosed in curly quotes. Here $1 and S2 means to type options 1 and 2. A $0 means to type the name of the shell script.
This function uses the echo command to display the a line of text. The two arguments here are John and R.
hello John R
arguments are like instructions or variables for commands. They include - /dir/filenames, punctuation ~ ' ! and spaces.
When you run the shell called hello in Terminal, it displays the following line of text.
Hello, John R
Here is the shell function as above.
#! /bin/bash
hello() {
echo -n "Hello, "
echo option1 option2
}
hello John R
When any command executes successfully, it returns an exit status of 0, zero. If instead it returns another number, then something is wrong with the command.
Double quotes " are needed for commands which include expansions but they also work with other commands and are easier to read than single quotes. Expansions are characters like wildcards, like an asterisk * and a dollar $.
To use quotes with an expansion:
echo "Good day, $USER."
Here the expansion is $USER.
ken@ken-5AT-BD2:~$ echo "Good day, $USER."
Good day, ken.
user@user-U-H:~$
arguments need quotes " to tell commands that spaces between words are not arguments. With a quote missing, the command above does not work properly.
user@user-U-H:~$ echo "Good day, $USER.
>
or user@user-U-H:~$ echo Good day, $USER."
>
Bash reads command lines from left to right. If one part of a command is written before or after it should be, that commandline will fail and will sometimes delete or corrupt data.
The file called null in the /Dev directory /dev/null stays always empty and anything written to it will be lost and cannot be read.
To delete erase a file without sending it first to the trash basket:
rm file 2>/dev/null
user@user-U-H:~/Desktop/testfold$ ls
bugtest errors ipdetect quailprice.png sshsh tibet.mp3
user@user-U-H:~/Desktop/testfold$ rm ./sshsh 2>/dev/null
user@user-U-H:~/Desktop/testfold$ ls
bugtest errors ipdetect quailprice.png tibet.mp3
user@user-U-H:~/Desktop/testfold$
user@user-U-H:~/Desktop/testfold$ ls /dev/null
/dev/null
user@user-U-H:~/Desktop/testfold$
The file called sshsh was deleted from the ./ current directory without it being stored in the null file or the trash.
To write a bash shell script using Terminal and Gedit: -
Start Terminal
After the command prompt $, type this command to start Gedit and open a new file called hello678:
gedit /home/user/hello678.sh
While you are in the new hello file, type these bash and echo commands:
#! /bin/bash
echo "Hello John Rip"
Save the file in the text editor to /home/user/Desktop
Click the Terminal screen to go back to a new command prompt.
Type this chmod command to make the shell script executable:
$ chmod +x hello678.sh
To execute the script, type a ./ prefix before the filename.
$ ./hello678.sh
Press enter
See "Hello John Rip" printed to screen.
Find where the new shell.sh file is stored, /Desktop, /bin/bash, /tmp ?
A script is a text file full of command lines which tell Bash or another interpreter what to do. Script commands are the same as those run on the command line. Names of Bash scripts normally end in .sh. Each script starts with #! /bin/bash, or the name of another interpreter program other than Bash. Each command starts with the name of that command. Command names can be followed with options which start with a - hyphen. Two types of variables can follow that, inner variable which start with a hash and number like #1 ,and outside variable which start with a hash and letters like #bcd. arguments or parameters are other words for variables. Variables can be followed by conditions which often have expressions in square brackets [], functions which have curved and curly brackets, and loops. So in writing scripts, you can use commands, variables, conditions, functions and loops. A command interpreter like Bash by default runs or executes commands in scripts one at a time and one after the other from top to bottom. Conditional expressions begin with their name and end with their name spelled backwards, for example if and fi, case and esac. They can be combined by writing one after the other with two ampersands && in between them, or two || pipes. Loops make parts of a script repeat themselves. To stop a loop, type break on the next new line in the script. Functions are subscripts called by the main scripts. If a script is to call one subcommand out of a choice of several, depending on conditions, each of those subcommands ends with ;; a double semicolon. Anything typed after a # on a line is only a comment and is not executed. Bash will not execute a script which has a space in the wrong place or no space where one is needed. Sometimes ` backticks ` are used to execute a command in a script, the backtick being on the same key as the tilde ~.
To combine commands which are not in a script, see sudocombined.txt.
To tell Bash to start running the next command before the last command has finished, type an & ampersand sign at the end of each command line.
To run two programs at once, write a script like this in a text editor:
#1 /bin/bash
/usr/bin/free &
/usr/bin/gedit &
Save the script with a .sh shell suffix such as 2at1.sh into a folder such as ~/Scripts.
To make the script file executable:
$ chmod a+x filename
user@user-H64C-ED4:~$ chmod a+x ~/Scripts/2at1.sh
user@user-H64C-ED4:~$ cd ~/Scripts
user@user-H64C-ED4:~/Scripts$ ls
2at1.sh sum678.sh
There is the new script and its command name is 2at1.sh. Run the script with a command starting with ./ to show that it is in the current directory.
user@user-H64C-ED4:~/Scripts$ ./2at1.sh
user@user-H64C-ED4:~/Scripts$ total used free shared buff/cache available
Mem: 4041136 632088 2629504 12628 779544 3127940
Swap: 2089980 0 2089980
Gedit opens a new page for editing and Free shows how much space is free on the hard disk. Press ESC to go back to the prompt.
To run a script when you are not in the ~/Scripts directory:
user@user-H64C-ED4:/$ ~/Scripts/2at1.sh
user@user-H64C-ED4:/$ total used free shared buff/cache available
Mem: 4041136 1126632 1998388 47240 916116 2597756
Swap: 2089980 0 2089980
/Scripts is a directory made by the user.
To change the mode of a shell script to permit anybody to run or execute it:
$ chmod a+x scriptname.sh
To change permissions so that only the owner of a script can read or write to it or execute it:
$ chmod o-rwx scriptname.sh
To change which group a script belongs to so that other administrators can use it:
$ chgrp sudo scriptname.sh
To change ownership of a script so that only the one adminstrator can use it:
$ chown :root scriptname.sh
To recursively -R change ownership of a directory and all its subdirectories and files:
$ chown -R jack /home/user/Scripts
Here user root gives jack the Scripts.
The ./ typed at the start of a scriptname tells Bash that the script is in the current directory. Without a ./, Bash follows a path to other directories to try and find the script. To show these other directories:
user@user-H64C-ED4:~/Scripts$ echo $PATH
/home/user/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
user@user-H64C-ED4:~/Scripts$
To run this if example script:
user@user-H64C-ED4:/$ /home/user/Scripts/shdir.sh
Scripts directory is at ~/Scripts
2at1.sh router.sh shdir.sh sum678.sh
Change to Scripts directory. Type ./ before name of script.
user@user-H64C-ED4:/$
To write a script text file with an if condition in it:
#!/bin/bash
directory="/home/username/Scripts"
# bash check if directory exists
if [ -d $directory ]; then
echo "Scripts directory is at ~/Scripts"
else
echo "Scripts directory is not there"
fi
# change to Scripts directory.
ls /home/user/Scripts
echo "Change to Scripts directory. Type ./ before name of script."
To make the new script accessible and usable in terminal:
user@user-H64C-ED4:/$ chmod a+x ~/Scripts/shdir.sh
To run the if script in a terminal:
user@user-H64C-ED4:/$ /home/user/Scripts/shdir.sh
Scripts directory is at ~/Scripts
2at1.sh router.sh shdir.sh sum678.sh
Change to Scripts directory. Type ./ before name of script.
user@user-H64C-ED4:/$
To make a file executable, you set the executable bit, and for a shell script, the readable bit also:
$ chmod a+rx scriptname.sh
Then run the script:
$ ./scriptname.sh
To write a script that checks whether a computer's router is working:
Start Gedit or another text editor and write a script such as this:
#!/bin/bash
ip='route -n | grep UG | tr -s "" | cut -f 2 -d ""'
ping="/bin/ping"
echo "Checking to see whether router $ip is working ..."
$ping -c 5 $ip
Save the script as say router.sh into the ~/Scripts directory.
To activate the script, run chmod command:
user@user-H64C-ED4:~$ chmod a+x ~/Scripts/router.sh
user@user-H64C-ED4:~$
To run the bach script:
In Terminal, change to the ~/Scripts directory.
At the command prompt S type ./scriptname and press enter.
user@user-H64C-ED4:~$ cd ~/Scripts
user@user-H64C-ED4:~/Scripts$ ./router.sh
Checking to see whether router route -n | grep UG | tr -s "" | cut -f 2 -d "" is working ...
ping: unknown host route
user@user-H64C-ED4:~/Scripts$
That script is supposed to tell Linux to ping the router 5 times and show the IP address and statistics if the router is up and working. But the script has a bug in it.
see scripting.txt
To list all files of one type in the current directory you can use the echo command.
user@yne3:~$ cd ~/Desktop
user@yne3:~/Desktop$ echo *.png
optus$90overcharge.png sb26519.png
user@yne3:~/Desktop$
But usually you use instead the list command.
user@yne3:~/Desktop$ ls *.odg
otus$90overcharge.odg
user@yne3:~/Desktop$
To print on screen the exact name of the current user, use a $ sign with this command in caps.
user@yne3:~/Desktop$ echo $USER
user
user@yne3:~/Desktop$
GCC is a program compiler of Linux software. It programs in C and C++ command language.
To see GCC commands in a manual:
e@yne3:~$ man gcc
Press the up and down arrows to scroll the manual and q to quit it.
To check whether GCC is installed, run
user@yne3:~$ gcc
gcc: fatal error: no input files
compilation terminated.
This shows that the compiler is installed.
To run a command for software development, the syntax is:
gcc -options filename
To find all the shells available in and supported by the system:
user@user-K-ED4:/$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
user@user-K-ED4:/$
To read information about using a commmand, type info commandname:
user@user-K-ED4:/$ info echo
To leave the info page, press q.
To find information about Info itself, run the Info program itself.
user@user-H64C-ED4:~$ info info
File: dir, Node: Top, This is the top of the INFO tree.
This is the Info main menu (aka directory node).
A few useful Info commands:
'q' quits;
'?' lists all Info commands;
'h' starts the Info tutorial;
'mTexinfo RET' visits the Texinfo manual, etc.
* Menu: ... ets
Press ? and type a search word.
Press arrow keys or PageDown key to scroll.
Press q to quit Info.
Info searches nodes which are pages linked together.
To use the shell, type a command after the $ at the command prompt. For example, to clear previous command sin Termnal:
$ clear
Type clear and press enter to execute the clear command.
Shell programming or scripting is writing more than one command into a text file and using Terminal to tell Bash to interpret and execute all the commands, one after another or in a special order.
To read input typed at a prompt of a shell script and show it as output on screen, run the read command:
read
See message.sh.
To write a shell script which uses the read command interactively: -
Start terminal
$ gedit ~/Desktop/sum678.sh
user@user-K-ED4:/$ gedit ~/Desktop/sum678.sh
In the editor, type this script in the file sum678.sh:
#! /bin/bash
read -p "Enter two numbers here:" x y
ans=$((x + y ))
echo "$x + $y = $ans"
Next save the text file and close it.
Back at the command prompt, type
user@user-K-ED4:/$ chmod +x ~/Desktop/sum678.sh
user@user-K-ED4:/$ ./sum678.sh
bash: ./sum678.sh: No such file or directory
user@user-K-ED4:/$ cd ~/Desktop/
user@user-K-ED4:~/Desktop$ ./sum678.sh
This shows the enter prompt where you type two numbers.
Enter two numbers here:6 5
6 + 5 = 11
user@user-K-ED4:~/Desktop$
Bash adds the two numbers and displays the ans answer as its output.
Once a script has been tested on the desktop as ok, save it in a directory such as /home/username/Scripts where scripts can be collected for reuse. To run the sum script, change to the Scripts directory:
user@user-H64C-ED4:~/Scripts$ ./sum678.sh
Enter two numbers here:1 6
1 + 6 = 7
user@user-H64C-ED4:~/Scripts$
End script names with .sh so they easily can be told apart from other types of files.
To manually mount a hard drive, CD or DVD drive or floppy drive so that it can be used by Linux, use the /media directory as the mount point place. Although the mount point is often /mnt, Debian Linux with Ubuntu automatically uses /media and /cdrom by default.
To make directories as mount points:
$ ls /media
floppy floppy0 user
Linux here mounts the system hard drive at /user, that being the username.
e@user-K-ED4:~$ sudo mkdir /media/hard
[sudo] password for user:
yne-K-ED4:~$ sudo mkdir /media/cddvd
user-K-ED4:~$ sudo mkdir /media/usb
user-K-ED4:~$ ls /media
cddvd floppy floppy0 hard usb user
Drive devices cdrom, dvd, fd, usb, sda and disk are listed with other devices in /dev.
yne-K-ED4:~$ ls /dev
autofs input ram4 tty1 tty47 ttyS25
block kmsg ram5 tty10 tty48 ttyS26
bsg kvm ram6 tty11 tty49 ttyS27 ... etc
To find where in the filing system Linux automatically mounts a cd or dvd drive:
Put a dvd disk into the cd drive of the computer and wait a moment while Linux automatically mounts it.
user@user-K-ED4:~$ ls /cdrom
Shows that this directory is empty.
user@user-K-ED4:~$ ls /media
cddvd floppy floppy0 hard usb user
user@user-K-ED4:~$ ls /media/cddvd
user@user-K-ED4:~$ ls /media/user
5KPhotos04101
That is the dvd mounted.
user@user-K-ED4:~$
So this Ubuntu Linux mounts dvds to the /media/username directory.
To check what is the device name of the hard drive the operating system is installed on, and other information:
yne-K-ED4:~$ gedit /etc/fstab
To manually mount a dvd disk using Linux: -
Use the file manager to mouse click and automatically unmount and eject any disk that is already mounted.
Insert the dvd to be mounted into the cd or dvd drive.
$ mount /dev/devicename /media/mountpoint
$ mount /dev/sr0 /media/cddvd
Here sr0 is the name given to the dvd by Linux and /cddvd is an empty directory mount point.
user@user-K-ED4:~$ sudo mount /dev/sr0 /media/cddvd
[sudo] password for user:
mount: /dev/sr0 is write-protected, mounting read-only
user@user-K-ED4:~$ ls /media/cddvd
4SEASONS Cosmi.ico KIDS ROME SPACE
AdbeRdr60_enu_full.exe DISK1.ID LANDMARK SAND&SEA STAINGL1
AMAZANML ... etc
The dvd is loaded.
Or try to mount a cd or dvd with these short commands which work with some Linux systems:
mount /cdrom
user@user-K-ED4:~$ mount /dev/cdrom
mount: can't find /dev/sr0 in /etc/fstab
user@user-K-ED4:~$
The fstab file would have to be edited for this command to work.
user@user-K-ED4:~$ mount /media/cdrom
mount: /media/cdrom: No such file or directory
user@user-K-ED4:~$ mount /cdrom
mount: can't find /cdrom in /etc/fstab
user@user-K-ED4:~$
There is a directory called /cdrom but no entry for it in the fstab file.
If you can't access your Windows partition from Linux, aren't able to mount your CD or write to your floppy as a normal user, or have problems with your CD-RW, you probably have a misconfigured /etc/fstab file. So, you can usually fix your mounting problems by editing your fstab file.
Here is an example of how it could be edited:
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0 .
The first column is the device name. The second column is the default mount point for the device. The third column is the file system type, which could be auto, ext2, swap, vfat or whatever. The fourth column is the mount options, which could be default. The fifth is the dump options and the sixth is the file system check options, numbered 0,1 or 2.
Make sure the mount point is a directory that already exists on your system. If the mount point directory does not exist, make it with the mkdir command. To be able to write to Windows partitions from Linux, format them as Vfat, that is FAT32. Vfat is the most reliable cross-platform file system type for floppy drives. Noauto means that the drive will not be automatically mounted when the computer starts. Nouser means that only root can mount the device. RW means the device can be read and written to. Ro means read only. Exec allows a binary file to be executed on the drive, such as DOS on a floppy. Sync is the option for a floppy drive because it means that files are copied to it as soon as you run the cp command, not later. Defaults uses the default options that are rw, suid, dev, exec, auto, nouser, and async. Dump is a backup utility and fsck is a file system check utility. A zero means that the utility will not be used on the device.
Here are two more examples of lines in the fstab file.
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0
The exec option allows a program to be executed from the CD compact disk. Here the zero means it cannot be executed.
To mount a drive:
mount
To unmount a drive, use a command like this:
umount
$ umount /dev/hdc
Here hdc is the system's name of the device.
A disk or usb memory stick or drive must be unmounted before it is ejected. Otherwise data will be lost.
user@user-K-ED4:~$ umount /media/cddvd
umount: /media/cddvd: umount failed: Operation not permitted
user@user-K-ED4:~$ sudo umount /media/cddvd
user@user-K-ED4:~$
Always safely remove or eject a USB stick before logging out or shutting down the computer. If some USB sticks are left in the computer when it is shut down, the computer will stall when rebooted.
To find system names of devices in use, their mount points and the amount of disk space they are using type:
$ df -h
yne-K-ED4:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 6.5M 389M 2% /run
/dev/sda1 114G 5.6G 103G 6% /
tmpfs 2.0G 256K 2.0G 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 395M 60K 395M 1% /run/user/1000
/dev/sr0 401M 401M 0 100% /media/user/5KPhotos041012
user@user-K-ED4:~$
See that the system calls the dvd drive sr0, and that the only hard drive mounted is called sda1. Linux calls IDE hard drive devices hda and Sata hard drives sda.
To remove write protect from a floppy disk, slide the small square hole shut on the disk, so that one hole is closed and the other is open. Otherwise Mount shows this message,
home@user-ID:~$ sudo mount /dev/fd0 /media/floppy0
mount: /dev/fd0 is write-protected, mounting read-only
The same mount, list and umount commands given below can be repeated for different floppy disks.
To mount a floppy disk:
Put it in the drive and run a command like this with the right device name and mount point,
home@user-ID:~$ sudo mount /dev/fd0 /media/floppy0
home@user-ID:
To show files on a floppy drive:
ls /media/floppy0
sel.jpg gard amsterdam roman jack
home@user-ID:~$
To open, read or edit a text file on a floppy disk:
home@user-ID:~$ gedit /media/floppy0/amsterdam
This tells Gedit that the file is called amsterdam and it is on a floppy disk mounted at the directory /media/floppy0/ .
To unmount a floppy disk:
home@user-ID:~$ sudo umount /dev/fd0 /media/floppy0
umount: /media/floppy0: not mounted
home@user-ID:~$
To write protect a floppy disk so that it is read only, slide the small square hole open on the disk so that both holes are open.
To copy files from a floppy drive to a directory on the hard drive:
home@user-ID:~$ ls /media/floppy0vian.htm vian.ZIP
home@user-ID:~$ cp /media/floppy0/vian.htm ~/Desktop/
home@user-ID:~$ cp /media/floppy0/vian.ZIP ~/Desktop/
home@user-ID:~$ ls ~/Desktop/
dosboxhow linuxsudo12 vian.ZIP
vian.htm
home@user-ID:~$
If the floppy bay does not have a disk in it, Linux shows this message:
home@user-ID:~$ sudo mount /dev/fd0 /media/floppy0
[sudo] password for username:
mount: /dev/fd0 is not a valid block device
home@user-ID:~$
To make Linux mount an old floppy drive formatted with DOS fat, sometimes this line might need to be typed and saved in the /etc/fstab file:
/dev/fd0 /media/floppy vfat noauto,user 0 0
Here the name of the floppy drive is fd0, the drive to mount it to is /floppy, the cd or dvd is formatted FAT, it will not be automatically mounted, and any user can mount it. Fstab applies this to all DOS floppy disks. Ubuntu usually mounts floppies to /media/floppy0 .
If Ubuntu cannot access floppy drives, install DosBox with its dependencies then try the mount command in Terminal again or try Drives and Files Manager. If some can be accessed but others cannot, the other floppies may need their permissions changed or they may be worn out.
-find Find program finds files with the same name or size.
To read all the Find commands and options,
user@user-X-ED4:~$ man find
To find a file by its name in . the current directory:
user@user-X-ED4:~/Desktop$ find . -name mirrorfa
./mirrorfail
That . means current directory, the option is -name, the filename is mirrorfa
To find a file by name in another directory, type the path to it:
user@user-X-ED4:~$ find /home/user/Desktop -name mirrorfa
/home/user/Desktop/mirrorfa
To ignore the case of letters in the filename, use the i option:
user@user-X-ED4:~/Desktop$ find . -iname Mirrors
./mirrors
To find directories d called thumbnails in the root / directory and subdirectories:user@user-X-ED4:~/Desktop$ sudo find / -type d -name thumbnails
[sudo] password for user:
find: ‘/run/user/1000/gvfs’: Permission denied
/home/user/Programs/Tor/tor-browser_en-US/Browser/.cache/thumbnails
/home/user/Programs/Tor/tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default/thumbnails
/home/user/.cache/mozilla/firefox/0i7mji06.default/thumbnails
/home/user/.cache/thumbnails
/media/user/2245-12FD/.Trash-999/files/Aopensave212/Business/Product/thumbnails
user@user-X-ED4:~/Desktop$
To find all files with the extension .jpg in the current directory and its subdirectories:
@user-X-ED4:~/Desktop$ find . -type f -name "*.jpg"
/home/user/Pictures/18460296669_792d7f00f2_c.jpg
To find all text files whose name is findhow in a current working directory.
$ find . -type f -name filename.php is the command
./filename.php is the expected output
user@user-X-ED4:~/Desktop$ find . -type f -name findhow.txt
user@user-X-ED4:~/Desktop$ find . -type f -name findhow.doc
user@user-X-ED4:~/Desktop$ find . -type f -name findhow
./findhow
Ubuntu File Manager lists plain text files without their extension on the /Desktop. So leave the extension .txt off the find command.
user@user-X-ED4:~/Desktop$ find . -type f -name findhow.doc
./findhow.doc
Here Find searched for and found a file with the same name as before but with a .doc document extension. This file was not found when the extension was left off the command.
To find in the working directory . files with their permissions perm set to executable x:
user-X-ED4:~/Desktop$ # find . -perm /a=x
user-X-ED4:~/Desktop$
There are none.
To find a single file called test.txt and remove it:
$ find . -type f -name "test.txt" -exec rm -f {} \;
user@user-X-ED4:~/Desktop$ find . -type f -name "test" -exec rm -f {} \;user@user-X-ED4:~/Desktop$ ls
18460296669_792d7f00f2_c.jpg linuxhow1st mirrors
2DO linuxsudo removed18
findhow linuxsudob start-tor-browser.desktop
findhow.doc mirrorfail ufwfirewall
user@user-X-ED4:~/Desktop$
Text file called test has gone.
To find and remove many files such as .mp3 or .txt, use:
$ find . -type f -name "*.txt" -exec rm -f {} \;
or $ find . -type f -name "*.mp3" -exec rm -f {} \;
user-X-ED4:~/Desktop$ ls
18460296669_792d7f00f2_c.jpg hahm10.jpg linuxsudob
2DO hahm14.jpg mirrorfail
findhow hahm15.jpg mirrors
findhow.doc hahm16.jpg removed18
hahm07.jpg linuxhow1st start-tor-browser.desktop
hahm09.jpg linuxsudo ufwfirewall
user@user-X-ED4:~/Desktop$ find . -type f -name "*.jpg" -exec rm -f {} \;
user@user-X-ED4:~/Desktop$ ls
2DO linuxhow1st mirrorfail start-tor-browser.desktop
findhow linuxsudo mirrors ufwfirewall
findhow.doc linuxsudob removed18
user@user-X-ED4:~/Desktop$
user@user-X-ED4:~/Desktop$ sudo find /tmp -type f -empty
[sudo] password for user:
/tmp/unity_support_test.0
/tmp/config-err-aCqe4h
user@user-X-ED4:~/Desktop$
To find all empty files on a directory path.
$ find /tmp -type f -empty
user@user-X-ED4:~/Desktop$ sudo find /tmp -type f -empty
[sudo] password for user:
/tmp/unity_support_test.0
/tmp/config-err-aCqe4h
user@user-X-ED4:~/Desktop$
Sudo administrator found two empty files in the /tmp directory for temporary files.
To find all empty directories under a path.
# find /tmp -type d -empty
If you see error messages like this below, use a sudo command.
find: ‘/tmp/systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-tor@default.service-Z17jWd’: Permission denied
/tmp/.font-unix
user@user-X-ED4:~/Desktop$ sudo find /tmp -type d -empty
/tmp/.XIM-unix
/tmp/systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-rtkit-daemon.service-DhqPKi/tmp
/tmp/systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-colord.service-LJ91e9/tmp
/tmp/.Test-unix
/tmp/systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-systemd-timesyncd.service-zG6yH8/tmp
/tmp/systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-tor@default.service-Z17jWd/tmp
/tmp/.font-unix
user@user-X-ED4:~/Desktop$
To find all hidden files, use this command.
$ find /tmp -type f -name ".*"
user@user-X-ED4:~/Desktop$ sudo find /tmp -type f -name ".*"
/tmp/.X0-lock
user@user-X-ED4:~/Desktop$
Found one file that does not show because its name starts with a . full stop. That file is not listed in the directory below.
user@user-X-ED4:~/Desktop$ ls /tmp | more
config-err-aCqe4h
systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-colord.service-LJ91e9
systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-rtkit-daemon.service-DhqPKi
systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-systemd-timesyncd.service-zG
6yH8
systemd-private-752a0e2188364eb1a64ba6a4607ac0e6-tor@default.service-Z17jWd
unity_support_test.0
user@user-X-ED4:~/Desktop$
To find a file called findhow.txt under the / root directory of owner user root.
$ find / -user root -name findhow.txt
find: ‘/run/user/1000/gvfs’: Permission denied
user@user-X-ED4:~/Desktop$ sudo find / -user username -name findhow
find: ‘/run/user/1000/gvfs’: Permission denied
/home/user/Desktop/findhow
/home/user/.local/share/Trash/files/findhow
/home/user/Documents/findhow
/media/user/red8gbusb/.Trash-1000/files/findhow
user@user-X-ED4:~/Desktop$
If type the user's name instead of root.
To find all .pdf files in a /home directory and subdirectories which belong to a user:
$ find /home -name *.pdf -user user
user-X-ED4:~/Desktop$ find /home -name *.pdf -user username
/home/user/Documents/sbdental/CCF20092018_00000b.pdf
/home/user/Documents/optus419my-bill.pdf
/home/user/Documents/Dec 2018ST.pdf
/home/user/Documents/acerguide.pdf
.... etc
To find all .txt files of a user under the /home directory.
$ find /home -user username -iname "*.txt"
The -i option says to ignore whether the filename is in upper or lower case.
user-X-ED4:~/Desktop$ find /home -user user -iname "*.txt"
/home/user/Programs/Tor/tor-browser_en-US/Browser/TorBrowser/Docs/Licenses/Tor.txt
/home/user/Programs/Tor/tor-browser_en-US/Browser/TorBrowser/Docs/ChangeLog.txt
/home/user/.mozilla/firefox/0i7mji06.default/enumerate_devices.txt
/home/user/.mozilla/firefox/0i7mji06.default/AlternateServices.txt
... etc
To find all files which have been accessed in the last 1 day.
$ find / -atime 1
user@user-X-ED4:~/Desktop$ find / -atime 1
... list of files accessed ...
/etc/nanorc
/etc/gai.conf
/boot/vmlinuz-4.8.0-36-generic
user@user-X-ED4:~/Desktop$
To find all the files which have been changed in last 1 hour.
# find / -cmin -60
This group of commands works on the root directory /.
Sometimes a # mark is used instead of a $ dollar to show where a command begins. It is not part of the command.
user-X-ED4:~/Desktop$ sudo find / -cmin -60
... list ...
/home/user/.config/dconf/user
/home/user/.config/ibus/bus
/home/user/.cache/upstart/unity-panel-service.log
/tmp
user@user-X-ED4:~/Desktop$
To find all the files which have been modified in last 1 hour.
# find / -mmin -60
To find all the files which are greater than 50MB and less than 100MB.
# find / -size +50M -size -100M
To find all 100MB files and delete them using one single command.
# find / -size +100M -exec rm -rf {} \;
Find all .mp3 files with more than 10MB and delete them using one single command. Here the rm remove command is executed to delete mp3 audio files.
# find / -type f -name *.mp3 -size +10M -exec rm {} \;
To find all the files which were modified 5 days ago.
$ find / -mtime 5
Find all Read Only files.
# find / -perm /u=r
To check the status of the network:
ip a
user@mail:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp5s3: mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
user@mail:~$
There the interface named enp5s3 is down, disabled.
To enable the network run the interface configuration program:
ifconfig interfacename up
user@mail:~$ sudo ifconfig enp5s3 up
[sudo] password for user:
user@mail:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp5s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
inet6 fe80::20f:b5ff:fefd:aff4/64 scope link
valid_lft forever preferred_lft forever
user@mail:~$
See enp5s3: BROADCAST,MULTICAST,UP,LOWER_UP
The network is up, enabled.
But after rebooting the computer, the network is down again by default - enp5s3: mtu 1500 qdisc noop state DOWN
To set up a network:
Set and change the IP address.
Set up and change the hostname.
Edit the host file.
To set and change an IP address:
Manually set a static IP address.
To find the interface, run netstat.
user@mail:~$ netstat -i
user@mail:~$ netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
enp5s3 1500 0 79434 0 0 0 58299 0 0 0 BMRU
lo 65536 0 7420 0 0 0 7420 0 0 0 LRU
user@mail:~$
The wired IPV4 IP address shown in Ubuntu Network settings is
192.168.1.102
The netmask is still
255.255.255.0
The IPv6 address is
fe80::f9db:6387:6faa:6878
The Default route is
192.168.1.1
and the DNS is the same
192.168.1.1
The connection name is
Ethernet connection 2
The IPv4 method is
Automatic DHCP
Those are the existing local network settings.
To show the current IP address a of the local computer:
ip a
user@mail:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp5s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.102/24 brd 192.168.1.255 scope global dynamic enp5s3
valid_lft 84494sec preferred_lft 84494sec
inet6 fe80::f9db:6387:6faa:6878/64 scope link
valid_lft forever preferred_lft forever
user@mail:~$
To set up the local IP address:
ifconfig
sudo ifconfig eth0 192.168.72.6 netmask 255.255.255.0
user@mail:~$ sudo ifconfig eth0 192.168.1.102 netmask 255.255.255.0
[sudo] password for user:
SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
SIOCSIFNETMASK: No such device
user@mail:~$
Try the other IP address
user@mail:~$ sudo ifconfig eth0 192.168.72.8 netmask 255.255.255.0
SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
SIOCSIFNETMASK: No such device
user@mail:~$
The IP address there has changed.
Ubuntu 18 used Network Manager, also called Network, but Ubuntu 20 uses Netplan to set up the static IP in its OS system. Netplan runs on the Terminal command line. It is not installed. Do not use either. Nmcli controls Network Manager from the terminal and does not work without it.
To set a Static IP address, edit /etc/network/interfaces
sudo nano /etc/network/interfaces
Add the lines below to /etc/network/interfaces. But change the IP to 192.168.1.102
auto eth1
iface eth1 inet static
address 192.168.72.8
netmask 255.255.255.0
gateway 192.168.72.1
dns-nameservers 8.8.8.8 4.4.2.2
But 8.8.8.8. is Google, use Namebright instead. Namebright's IP address is 172.67.15.112
Save the file and restart networking services.
To restart networking services.
sudo systemctl restart networking
To setup or change the hostname of Ubuntu OS, configured the file /etc/hostname.
To edit /etc/hostname:
sudo nano /etc/hostname
This file contains only the hostname of the file, change the name, and then save it.
user@mail:~$ sudo gedit /etc/network/interfaces
The interfaces text file shows only this.
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
user@mail:~$
Network commands in Linux are: IP, ifconfig, dhclient, ethtool, ss, netstat, nmap, tcpdump, mtr, ping, traceout, iperf.
Nmcli is a command for a network tool which does not automatically conflicts with other configurations but it nerelies on Network Manager.
See networkhow.txt
user@mail:~$ nmcli g
Error: NetworkManager is not running.
user@mail:~$
Network-Manager is Network gui. It creates new configuration files, sets itself as the default network renderer and takes control of all devices.Standard configuration files are overwritten by NetworkManager gui every time the network is restarted, including every reboot. So stop Network Manager. When it stops, the internet disconnects. Enable the systemd-networkd service instead.
To run System-Networkd:
systemd
user@mail:~$ sudo systemd
[sudo] password for user:
Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.
user@mail:~$
So systemd is installed.
To show help options for systemd:
systemd -h
systemd [OPTIONS...]
Starts up and maintains the system or user services.
-h --help Show this help
--test Determine startup sequence, dump it and ex
--no-pager Do not pipe output into a pager
--dump-configuration-items Dump understood unit configuration items
--unit=UNIT Set default unit
--system Run a system instance, even if PID != 1
--user Run a user instance
--dump-core[=BOOL] Dump core on crash
--crash-vt=NR Change to specified VT on crash
--crash-reboot[=BOOL] Reboot on crash
--crash-shell[=BOOL] Run shell on crash
--confirm-spawn[=BOOL] Ask for confirmation when spawning process
--show-status[=BOOL] Show status updates on the console during
--log-target=TARGET Set log target (console, journal, kmsg, jo
--log-level=LEVEL Set log level (debug, info, notice, warnin
--log-color[=BOOL] Highlight important log messages
--log-location[=BOOL] Include code location in log messages
--default-standard-output= Set default standard output for services
--default-standard-error= Set default standard error output for serv
lines 1-23
Type q to quit.
To stop Network Manager gui program:
systemctl stop NetworkManager
To disable Network Manager:
systemctl disable NetworkManager
user@mail:~$ systemctl disable NetworkManager
Removed symlink /etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service.
Removed symlink /etc/systemd/system/multi-user.target.wants/NetworkManager.service.
user@mail:~$
Network manager stays disabled after the computer is rebooted.
To check that network manager is still disabled after rebooting the computer:
user@mail:~$ systemctl status NetworkManager -l
● NetworkManager.service - Network Manager
Loaded: loaded (/lib/systemd/system/NetworkManager.service; disabled; vendor
Active: inactive (dead)
Apr 29 10:40:46 mail.postbox22.com systemd[1]: Network Manager is not active.
lines 1-5/5 (END)
To show f Network Manager is enabled and who is the manager and who is the client:
systemctl status NetworkManager -l
user@mail:~$ systemctl status NetworkManager -l
● NetworkManager.service - Network Manager
Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor p
Active: active (running) since Fri 2022-04-29 09:20:16 AEST; 1h 12min ago
Main PID: 1133 (NetworkManager)
CGroup: /system.slice/NetworkManager.service
├─1133 /usr/sbin/NetworkManager --no-daemon
├─1472 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helpe
└─1508 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts
Apr 29 09:20:26 mail.postbox22.com NetworkManager[1133]: [1651188026.583
Apr 29 09:20:26 mail.postbox22.com NetworkManager[1133]: [1651188026.583
Apr 29 09:20:28 mail.postbox22.com dhclient[1717]: XMT: Solicit on enp5s3, inter
Apr 29 09:20:32 mail.postbox22.com dhclient[1717]: XMT: Solicit on enp5s3, inter
Apr 29 09:20:40 mail.postbox22.com dhclient[1717]: XMT: Solicit on enp5s3, inter
Apr 29 09:20:55 mail.postbox22.com dhclient[1717]: XMT: Solicit on enp5s3, inter
Apr 29 09:21:09 mail.postbox22.com NetworkManager[1133]: [1651188069.585
Apr 29 09:21:09 mail.postbox22.com NetworkManager[1133]: [1651188069.585
Apr 29 09:21:09 mail.postbox22.com NetworkManager[1133]: [1651188069.586
Apr 29 09:21:09 mail.postbox22.com NetworkManager[1133]: [1651188069.586
lines 1-19/19 (END)
Type q to exit.
To check if ethotool is installed:
user@mail:~$ ethtool
ethtool: bad command line argument(s)
For more information run ethtool -h
user@mail:~$
Yes, it is installed.
Configuration options
There are many configuration options for the interface configuration files. These are some of the more common options:
DEVICE: The logical name of the device, such as eth0 or enp0s2.
HWADDR: The MAC address of the NIC that is bound to the file, such as 00:16:76:02:BA:DB
ONBOOT: Start the network on this device when the host boots. Options are yes/no. This is typically set to "no" and the network does not start until a user logs in to the desktop. If you need the network to start when no one is logged in, set this to "yes".
IPADDR: The IP Address assigned to this NIC such as 192.168.0.10
BROADCAST: The broadcast address for this network such as 192.168.0.255
NETMASK: The netmask for this subnet such as the class C mask 255.255.255.0
NETWORK: The network ID for this subnet such as the class C ID 192.168.0.0
SEARCH: The DNS domain name to search when doing lookups on unqualified hostnames such as "example.com"
BOOTPROTO: The boot protocol for this interface. Options are static, DHCP, bootp, none. The "none" option defaults to static.
GATEWAY: The network router or default gateway for this subnet, such as 192.168.0.254
ETHTOOL_OPTS: This option is used to set specific interface configuration items for the network interface, such as speed, duplex state, and autonegotiation state. Because this option has several independent values, the values should be enclosed in a single set of quotes, such as: "autoneg off speed 100 duplex full".
DNS1: The primary DNS server, such as 192.168.0.254, which is a server on the local network. The DNS servers specified here are added to the /etc/resolv.conf file when using NetworkManager, or when the peerdns directive is set to yes, otherwise the DNS servers must be added to /etc/resolv.conf manually and are ignored here.
DNS2: The secondary DNS server, for example 8.8.8.8, which is one of the free Google DNS servers. Note that a tertiary DNS server is not supported in the interface configuration files, although a third may be configured in a non-volatile resolv.conf file.
TYPE: Type of network, usually Ethernet. The only other value I have ever seen here was Token Ring but that is now mostly irrelevant.
PEERDNS: The yes option indicates that /etc/resolv.conf is to be modified by inserting the DNS server entries specified by DNS1 and DNS2 options in this file. "No" means do not alter the resolv.conf file. "Yes" is the default when DHCP is specified in the BOOTPROTO line.
USERCTL: Specifies whether non-privileged users may start and stop this interface. Options are yes/no.
IPV6INIT: Specifies whether IPV6 protocols are applied to this interface. Options are yes/no.
If the DHCP option is specified, most of the other options are ignored. The only required options are BOOTPROTO, ONBOOT and HWADDR. Other options that you might find useful, that are not ignored, are the DNS and PEERDNS options if you want to override the DNS entries supplied by the DHCP server.
Configuration file examples
This example network interface configuration file, ifcfg-eth0, defines a static IP address configuration for a CentOS 6 server installation.
# Intel Corporation 82566DC-2 Gigabit Network Connection
DEVICE=eth0
HWADDR=00:16:76:02:BA:DB
ONBOOT=yes
IPADDR=192.168.0.10
BROADCAST=192.168.0.255
NETMASK=255.255.255.0
NETWORK=192.168.0.0
SEARCH="example.com"
BOOTPROTO=static
GATEWAY=192.168.0.254
DNS1=192.168.0.254
DNS2=8.8.8.8
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
Use Namebright instead of Google 8.8.8.8. Namebright's IP address is 172.67.15.112 and its DNS number is 10.1.1.123
See postbox22nb.png file for namebright details.
This file starts the interface on boot, assigns it a static IP address, defines a domain and network gateway, specifies two DNS servers, and does not allow non-root users to start and stop the interface.
The following interface configuration file, ifcfg-eno1, provides a DHCP configuration for a desktop workstation.
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=no
IPV6_DEFROUTE=no
IPV6_FAILURE_FATAL=no
NAME=eno1
UUID=a67804ff-177a-4efb-959d-c3f98ba0947e
ONBOOT=yes
HWADDR=E8:40:F2:3D:0E:A8
IPV6_PEERDNS=no
IPV6_PEERROUTES=no
In this second configuration file example, the DHCP entries, IP address, the search domain, and all other network information are not defined because they are supplied by the DHCP server. Configuration items like the DNS servers can be overridden in the interface configuration file by adding DNS1 and DNS2 lines, as in the previous static configuration example.
Note that this second example contains a UUID line. As far as I can determine, this line has no effect on the functionality of the configuration file. I usually comment it out or even delete it and have never experienced a detrimental effect on my network.
In both interface configuration files, the HWADDR line specifies the MAC address of the physical network interface. This binds the physical interface to the interface configuration file. You must change the MAC address in the file if you replace the interface.
There are a couple ways to locate the MAC address of a NIC. I usually use the ifconfig command which shows all installed NICs, thier MAC address and various statistics. Many new NICs have their MAC address printed on the box or labelled on the NIC itself. However, most interface configuration files are generated automatically during installation or when the NIC is first detected after being newly installed, and the MAC address is included as part of the new interface configuration file.
The ONBOOT line specifies that the interface is to be activated at startup time. If this line is changed to "no" the interface will have to be activated either manually, or by NetworkManager after a user logs in.
The USERCTL line specifies that non-privileged users cannot manage the interface; that is they cannot turn it on and off. Setting this parameter to "yes" allows regular users to activate and deactivate the interface.
Notice that the lines in the interface configuration files are not sequence-sensitive, and work just fine in any order. By convention, the option names are in uppercase and the values are in lowercase. Option values can be enclosed in quotes, but that is not necessary unless the value is more than a single word or number.
LAN
There are two types of local area networks LAN: peer to peer networks and client server networks. In client-server networks, some computers act as servers and others act as clients. A server is a computer that provides network resources and services to other computers when they rask for it. A client is a computer running a program that asks for a service from a server. A peer-to-peer network is two or more devices, usually a computers, connected and sharing resources. Computers in a peer network are connected through a single server that enables the transfer of files from one computer to the other. In a peer-to-peer network, each computer can act as a client and as a server. There is no central server.
Network software
To setup a P2P network, run n2n, OpenVPN, OpenSwan or PPTP.
To install pptpd on Ubuntu or Debian:
$ sudo apt-get install pptpd
To check whether IP forwarding is enabled:
cat /proc/sys/net/ipv4/ip_forward
If that command shows a number 1, then forwarding is enabled.
user@mail:~$ cat /proc/sys/net/ipv4/ip_forward
0
user@mail:~$
The zero 0 means forwarding is disabled.
To enable IP forwarding on the fly, run a sysctl command. IP forwarding will be activated immediately without rebooting.
sudo sysctl -w net.ipv4.ip_forward=1
IP forwarding enabled by a sysctl command does not remain active across reboots and becomes disabled after rebooting.
To enable IP forwarding for IPv6:
sudo sysctl -w net.ipv6.conf.all.forwarding=1
To enable IP forwarding permanently, edit the /etc/sysctl.conf file.
sudo vi /etc/sysctl.conf
net.ipv4.ip_forward=1 # For IPv4
net.ipv6.conf.all.forwarding=1 # For IPv6
Then reload sysctl.conf.
To reload the sysctl.conf file:
sudo sysctl -p /etc/sysctl.conf
To restart networking and activate the changes:
sudo /etc/init.d/networking restart
or sudo service network restart
To configure PPTP VPN server, add localip server and remoteip client IP addresses to the file called /etc/pptpd.conf.
sudo vi /etc/pptpd.conf
or type gedit instead of vi.
localip 10.0.0.1
remoteip 10.0.0.2,10.0.0.10-30
Localip is the IP address of the VPN server.
Remoteip is the IP address of the VPN client.
To configure local DNS servers, edit /etc/ppp/pptpd-options something like this.
sudo vi /etc/ppp/pptpd-options
ms-dns 8.8.8.8
ms-dns 8.8.4.4
Those numbers are for public DNS servers provided by Google, for example.
To configure user authentication using CHAP, edit /etc/ppp/chap-secrets like this.
sudo vi /etc/ppp/chap-secrets
clientname pptpd dfs *
or say george pptpd dfs *
Here George is a client, pptpd is a server, dfs is secret, and the asterist * allows any IP address.
To restart pptpd daemon:
sudo /etc/init.d/pptpd restart
If the VPN server is behind a proxy, set up port forwarding on TCP port 1723, which is a VPN control channel.
Other computers with Linux or Windows operating systems OS can connect to P2P virtual private network.
Freelan uses public and private keys - https://www.freelan.org
RetroShare is an open source cross-platform, private and secure decentralized communication system. It lets you securely chat, share photos, videos, and more, using OpenPGP to authenticate peers and OpenSSL to encrypt all communication. Retroshare creates encrypted connections to your friends. Nobody can spy on you. Retroshare is completely decentralized. This means there are no central servers. It is entirely Open-Source and free. There are no costs, no ads and no Terms of Service.
LimeWire and Gnutella
BitTorrent is for filesharing on P2P networks.
Wget - To check access to a website and show its IP address:
wget webaddress
user:~$ wget postbox22.com
--2022-10-21 08:52:54-- http://postbox22.com/
Resolving postbox22.com (postbox22.com)... 195.201.179.80
Connecting to postbox22.com (postbox22.com)|195.201.179.80|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 614 [text/html]
Saving to: 'index.html.1’
index.html.1 100%[===================>] 614 --.-KB/s in 0s
2022-10-21 08:52:56 (59.5 MB/s) - 'index.html.1’ saved [614/614]
user:~$
That is a new website that has not been propagated on the net or launched yet.
To check if a web address has a web page online:
user@mail:~$ wget www.postbox22.com
--2022-04-28 10:52:49-- http://www.postbox22.com/
Resolving www.postbox22.com (www.postbox22.com)... failed: Name or service not known.
wget: unable to resolve host address ‘www.postbox22.com’
user@mail:~$
To show the configuration of the network, including IP address, subnet mask and interface settings, run IP.
To display IP addresses for all interfaces, type:
ip addr
user@mail:~$ ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp5s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.102/24 brd 192.168.1.255 scope global dynamic enp5s3
valid_lft 75762sec preferred_lft 75762sec
inet6 fe80::f9db:6387:6faa:6878/64 scope link
valid_lft forever preferred_lft forever
user@mail:~$
To specify a particular interface:
ip addr show interfacename
user@mail:~$ ip addr show enp0s3
Device "enp0s3" does not exist.
user@mail:~$
That is the wrong interface. The right interface name is shown in the output above as enp5s3.
user@mail:~$ ip addr show enp5s3
2: enp5s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.102/24 brd 192.168.1.255 scope global dynamic enp5s3
valid_lft 75384sec preferred_lft 75384sec
inet6 fe80::f9db:6387:6faa:6878/64 scope link
valid_lft forever preferred_lft forever
user@mail:~$
To display route and link information:
ip route
user@mail:~$ ip route
default via 192.168.1.1 dev enp5s3 proto static metric 100
169.254.0.0/16 dev enp5s3 scope link metric 1000
192.168.1.0/24 dev enp5s3 proto kernel scope link src 192.168.1.102 metric 100
user@mail:~$
To check if the computer is connecting through the internet router:
user@mail:~$ ip link show interfacename
Device "interfacename" does not exist.
user@mail:~$
The computer is not connected to the internet.
To show the IP link:
ip link show interfacename
user@mail:~$ ip link show enp0s3
Device "enp0s3" does not exist.
user@mail:~$
Try the right name of the interface device, as shown above.
user@mail:~$ ip link show enp5s3
2: enp5s3: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
user@mail:~$
To manage network connections, run Nmcli from the terminal command line, not the Network gui, using this command:
nmcli
To show the con connection link name, user identifier UID, type and device name:
nmcli con
user@mail:~$ nmcli con
NAME UUID TYPE DEVICE
Ethernet connection 2 3c6ecea4-6407-48cf-8b1e-d88b387b8c04 802-3-ethernet enp5s3
Ethernet connection 1 62e7afd1-9760-4b30-a4a1-cf150cb2d0d6 802-3-ethernet --
Wired connection 1 94554e83-d0d6-3071-a157-c06852cb6e5c 802-3-ethernet --
user@mail:~$
To check that the interface is enabled:
nmcli dev status
user@mail:~$ nmcli dev status
DEVICE TYPE STATE CONNECTION
enp5s3 ethernet connected Ethernet connection 2
lo loopback unmanaged --
user@mail:~$
Most Linux servers are configured with static IP addresses. But workstations and other devices are likely to be dynamic host configuration protocol (DHCP) clients. These devices lease an IP address configuration from a DHCP server.
To drop and then lease an IP address configuration from the DHCP server, run dhclient. First run the command with no options then with an -r option to initiate the new lease.
dhclient
then dhclient -r
To check or reconfigure network interfaces:
ethtool interfacename
ethtool enp0s3
user@mail:~$ ethtool enp5s3
Settings for enp5s3:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Advertised pause frame use: Symmetric Receive-only
Advertised auto-negotiation: Yes
Link partner advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Link partner advertised pause frame use: Symmetric
Link partner advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: MII
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Cannot get wake-on-lan settings: Operation not permitted
Current message level: 0x00000033 (51)
drv probe ifdown ifup
Link detected: yes
user@mail:~$
To show current connections to the system and socket statistics, run ss or netstat utility.
ss
user@mail:~$ ss -4
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
user@mail:~$ ss -4 state listening
Netid Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp 0 5 127.0.1.1:domain *:*
tcp 0 100 *:smtp *:*
tcp 0 100 *:2525 *:*
user@mail:~$
That is port number 2525 and local domain IP .127.0.1.1
To show output for specific connection, type the IP address of the destination.
ss dst ipnumber
user@mail:~$ ss dst 127.0.1.1
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
user@mail:~$ ss dst 192.168.1.102
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
user@mail:~$
To scan for open ports on remote systems, run execute use Network mapper, nmap.
To scan the network:
nmap subnetnumber
user@mail:~$ nmap 192.168.0.0
Starting Nmap 7.01 ( https://nmap.org ) at 2022-04-28 13:24 AEST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.04 seconds
user@mail:~$
To show confirm the status of port:
user@mail:~$ nmap -p portnumber ipnumber
user@mail:~$ nmap -p 53 192.168.0.0
Starting Nmap 7.01 ( https://nmap.org ) at 2022-04-28 13:37 AEST
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.04 seconds
user@mail:~$
To show how all connections on a network are being used and what kind of data is flowing through them, run tcpdump:
tcpdump -i interfacename
An interface name starts with an e and looks like this enp0s3.
user@mail:~$ sudo tcpdump -i enp5s3
[sudo] password for user:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp5s3, link-type EN10MB (Ethernet), capture size 262144 bytes
13:49:25.130852 IP6 fe80::86d8:1bff:fe1f:7399 > ip6-allnodes: ICMP6, router advertisement, length 32 etc
Press ctrl-c to stop scanning.
^C
44 packets captured
61 packets received by filter
17 packets dropped by kernel
user@mail:~$
To specify traffic to or from a given IP address:
tcpdump host ipnumber
eg tcpdump host 10.0.0.42
To show network connections output for only one port:
tcpdump port number
user@mail:~$ sudo tcpdump port 25
[sudo] password for user:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp5s3, link-type EN10MB (Ethernet), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
user@mail:~$
To show network performance and dropped packets of data, run an mtr command:
mtr localhost
user@mail:~$ mtr localhost
MTC monitors the network and shows output.
To close the output, press ctrl-c.
user@mail:~$
The output can show which routers are performing poorly and other troubleshooting information.
To show only output on IPv4:
rin mtr with the -4 option.
To show the bandwidth available for the performance of a computer server:
iperf
user@mail:~$ iperf
The program 'iperf' is currently not installed. You can install it by typing:
sudo apt install iperf
user@mail:~$
To designate the destination device as the target server, use the -s option:
iperf -s
To run iperf in client -c mode, type the IP address of target server.
iperf -c 10.0.0.5
Here 10.0.0.5 is the ip address of the server.
To specify the number of parallel -P connections to the target:
iperf -P 30 -c 10.0.0.5
user@mail:~$ sudo apt-get install iperf
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
iperf
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 51.0 kB of archives.
After this operation, 184 kB of additional disk space will be used.
Get:1 http://mirrors.edge.kernel.org/ubuntu xenial/universe amd64 iperf amd64 2.0.5+dfsg1-2 [51.0 kB]
Fetched 51.0 kB in 1s (36.3 kB/s)
Selecting previously unselected package iperf.
(Reading database ... 174583 files and directories currently installed.)
Preparing to unpack .../iperf_2.0.5+dfsg1-2_amd64.deb ...
Unpacking iperf (2.0.5+dfsg1-2) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Setting up iperf (2.0.5+dfsg1-2) ...
user@mail:~$
For two hosts to communicate on the same network using TCP/IP model, both hosts need a unique IP address.
To obtain an IP address for a host manually, configure the network interface and assign an IP address by hand. The manual network configuration is called static configuration, which means that a host’s IP address does not change unless it’s changed manually by the user or system administrator.
DHCP assigns an IP address to each host automatically. DHCP guarantees that all hosts on the network have a unique IP address. But each IP address keeps changing, is not static. So do not use DHCP for a personal mail server or a tiny network.
To install dhcp:
$ sudo apt install isc-dhcp-server
To restart DHCP:
$ sudo systemctl restart isc-dhcp-server
Linux Mint:
To show a list of current internet items:
ifconfig
user@mail:~$ ifconfig
enp5s3 Link encap:Ethernet HWaddr 00:0f:b5:fd:af:f4
inet addr:192.168.1.102 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::f9db:6387:6faa:6878/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:72655 errors:0 dropped:0 overruns:0 frame:0
TX packets:64381 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:41905229 (41.9 MB) TX bytes:10900662 (10.9 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:13624 errors:0 dropped:0 overruns:0 frame:0
TX packets:13624 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:1905028 (1.9 MB) TX bytes:1905028 (1.9 MB)
user@mail:~$
The current router or ethernet connection is shown at the top of the list as a name beginning with e, like eth0 or enp5s3. The name of the item to change is the one at the start of the list, in the top left corner. Here it is the router interface device enp5s3.
The inet address line shows the IP and netmask numbers. The mask number is usually 255.255.255.0
Before changing the configuration, stop the network manager.
To stop Network Manager from changing the manual settings on rebooting the computer:
Start the settings network gui program and select manual settings instead of automatic dhcp. Do not use DHCP.
ifconfig eth0 192.168.1.3
To change the IP address of the router interface item, run this command with the right eth0 number and IP address number:
sudo ifconfig interfacename ipaddress netmask 255.255.255.0 up
To assign an IP of 192.168.2.100 to an ethernet connection eth0, eg, type sudo ifconfig eth0 192.168.0.100 netmask 255.255.255.0
To set a static ip address by hand, run the commands ip and ifconfig.
user@mail:~$ ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:316 errors:0 dropped:0 overruns:0 frame:0
TX packets:316 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:27568 (27.5 KB) TX bytes:27568 (27.5 KB)
user@mail:~$
ifconfig etho 192.168.1.3 netmask 255.255.255.0 up
To set define the gateway as the default:
route add default gw 192.168.1.1
eg route add default gw 192.168.1.1
To add a DNS server run this echo command with the number of the DNS nameserver. The number here is that of Google, 8.8.8.8 but use the name of Namebright or another name server instead. Namebright's nameserver number is 10.1.1.123
echo "nameserver 8.8.8.8" > /etc/resolv.conf
Type any different DNS server address rather that 8.8.8.8.
See postbox22nb.png file for namebright details.
user@mail:~$ sudo echo "nameserver 10.1.1.123" > /etc/resolv.conf
bash: /etc/resolv.conf: Permission denied
user@mail:~$
To set the DNS domain name server:
echo "nameserver 1.2.2.1" >/resolv.conf
user@mail:~$ sudo echo "nameserver 1.2.2.1" >/resolv.conf
bash: /resolv.conf: Permission denied
user@mail:~$
To check the new IP address:
ifconfig
Find the item on the list and look at the address to the right of the item name. See the IP address that has just been assigned.
To find the public IP address of the server, send a request to the HTTP servers on the internet. By default, both public and private IP addresses will remain the same.
To use IP instead of Ifconfig to view your network connections:
ip a
Find the network connection to be changed listed at the right.
To switch change to the network scripts directory:
cd /etc/sysconfig/network-scripts
To list what is in that directory:
ls
See the current connection name in the upper-left side of the network option results.
To open the network options for the connection:
sudo gedit ifcfg-network name
See the network properties in the editor.
eg For a network named "eno12345678", type ifcfg-eno12345678
To edit network information, change the following values:
BOOTPROTO - Change dhcp to none
Any IPV6 entry - Delete any IPV6 entries entirely by moving the cursor to the I on the left and pressing Del.
ONBOOT - Change no to yes
To enter a new IP category:
Press enter to go down a line from the ONBOOT category.
Type in IPADDR= and enter the IP address that you want to use then press enter.
eg To use 192.168.2.23 as your IP address, type in IPADDR=192.168.2.23 and press enter.
To enter netmask, gateway, and DNS information:
Type in PREFIX=24 and press enter. Also enter NETMASK=255.255.255.0 here.
Type in GATEWAY=192.168.2.1 and press enter. Change the gateway address if different.
To save and exit the file, use the file menu or type :wq and press enter.
To install dhcpcd, run apat-get with the internet connected:
sudo apt-get install dhcpcd5
user@mail:~$ sudo apt-get install dhcpcd5
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
dhcpcd-gtk
The following NEW packages will be installed:
dhcpcd5
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 149 kB of archives.
After this operation, 371 kB of additional disk space will be used.
Err:1 http://mirrors.us.kernel.org/ubuntu xenial/universe amd64 dhcpcd5 amd64 6.10.1-1
Temporary failure resolving 'mirrors.us.kernel.org'
E: Failed to fetch http://mirrors.us.kernel.org/ubuntu/pool/universe/d/dhcpcd5/dhcpcd5_6.10.1-1_amd64.deb Temporary failure resolving 'mirrors.us.kernel.org'
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
user@mail:~$
Connect to the internet before installing the program.
To show network settings:
ifconfig
pete@pete-ID:~$ ifconfig
Command 'ifconfig' not found, but can be installed with:
sudo apt install net-tools
pete@pete-ID:~$
pete@pete-ID:~$ sudo apt-get install net-tools
[sudo] password for tom7:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
net-tools etc
pete@pete-ID:~$ ifconfig
enp5s3: flags=4163 mtu 1500
inet 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::9e09:992b:2386:46c9 prefixlen 64 scopeid 0x20
ether 00:0f:b5:fd:af:f4 txqueuelen 1000 (Ethernet)
RX packets 7882 bytes 7100955 (7.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4761 bytes 503741 (503.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 660 bytes 61753 (61.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 660 bytes 61753 (61.7 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pete@pete-ID:~$
user@user-Inspiron-518:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:21:9b:0d:e9:c6
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::221:9bff:fe0d:e9c6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:25199 errors:0 dropped:0 overruns:0 frame:0
TX packets:14299 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19726906 (19.7 MB) TX bytes:2294011 (2.2 MB)
Interrupt:43 Base address:0x8000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1063 errors:0 dropped:0 overruns:0 frame:0
TX packets:1063 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:100417 (100.4 KB) TX bytes:100417 (100.4 KB)
user@user-Inspiron-518:~$
There are the IP address, subnet mask and other settings.
The IP address and netmask or subnet mask are on the line beginning with inet
inet addr:192.168.1.101
Mask:255.255.255.0
The broadcast address is on the same line
Bcast:192.168.1.255
The ethernet interface is at top left
eth0
The local loopback address is
127.0.0.1
and the local mask is
255.0.0.0
The Mac or HW hardware address is on the top line
00:21:9b:0d:e9:c6
If no ip address is shown then it has not been set.
First copy the settings then disable Network Manager so that it does not automatically overrule settings made by Ifconfib.
To set the ip address of a device or computer system:
ifconfig networkinterface ipaddress
eg ifconfig eth0 192.168.1.101
The mac address is assigned by the maker of the computer.
To set the subnet mask:
ifconfig networkinterface ipaddress netmask netmaskaddress
eg ifconfig eth0 192.168.10.21 netmask 255.255.255.0
To set the network gateway gw to the computer:
route
route add default gw gatewayip networkinterface
eg route add default gw 192.168.10.1 eth0
To show the network settings:
route -n
pete@pete-ID:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 enp5s3
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp5s3
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp5s3
pete@pete-ID:~$
user@user-Inspiron-518:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
user@user-Inspiron-518:~$
The gateway ip address there is
192.168.1.1
To manage and query network interface parameters:
ifconf
Ifconf is short for interface configuration.
To show display the current network configuration; set up an ip address, netmask or broadcast address to a network interface; create an alias for the network interface; set up a hardware address; and enable or disable network interfaces:
ifconfig
Tecmint says the networking command ifconfig is deprecated and has been replaced by the ip command.
Ifconfig, route, nameif, iwconfig, iptunnel, netstat and arp all come in a package called net-tools. These commands are enought to configure a network although the IP commands are better for more recent kernels of Linux. As an alternative, IP does everything that the net-tools do and more.
Ip commands do not seem to conflict with ifconfig commands.
To show all inerfaces whether they are enabled or disabled:
ip a
pete@pete-ID:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp5s3: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.102/24 brd 192.168.1.255 scope global dynamic noprefixroute enp5s3
valid_lft 75351sec preferred_lft 75351sec
inet6 fe80::9e09:992b:2386:46c9/64 scope link noprefixroute
valid_lft forever preferred_lft forever
pete@pete-ID:~$
user@user-Inspiron-518:~$ ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:21:9b:0d:e9:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.101/24 brd 192.168.1.255 scope global eth0
inet6 fe80::221:9bff:fe0d:e9c6/64 scope link
valid_lft forever preferred_lft forever
user@user-Inspiron-518:~$
To enable or disable the ARP protocol to be used with a specific network interface:
ip link set dev eth0 arp on
or ip link set dev eth0 arp off
By default, the system does not retain the changes permanently. Once a Linux server is resatarted, the newly modified state will be lost.
To make your adjustments permanent, add the commands to a startup script or edit the distro-specific configuration files.
To display neighbour tables with MAC addresses of devices in the system:
ip neigh show
user@user-Inspiron-518:~$ ip neigh show
fe80::86d8:1bff:fe1f:7399 dev eth0 lladdr 84:d8:1b:1f:73:99 router STALE
192.168.1.1 dev eth0 lladdr 84:d8:1b:1f:73:99 STALE
user@user-Inspiron-518:~$
Stale means a valid yet unreachable entry.
Reachable means a valid entry which is reachable until its timeout expires.
Permanent means an everlasting entry that only an administrator can remove.
Dealay means that the kernel is still waiting for validation from the stale entry.
To assign an ip address and a netmask to bring the interface online:
ifconfig interfacename ipaddress netmask macaddress
eg ifconfig eth2 10.1.10.156 netmask 255.255.255.0
To verify check that the device is online:
ifconfig devicename
eg ifconfig eth2
To temporarily switch the network device offline:
ifconfig devicename down
eg ifconfig eth2 down
Then ifconfig eth2
and route
To enable or disable the network interface, run ip and ifconfig.
To display information about the network interface card that is used on the Linux system:
ip a
user@user-Inspiron-518:~$ ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:21:9b:0d:e9:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.101/24 brd 192.168.1.255 scope global eth0
inet6 fe80::221:9bff:fe0d:e9c6/64 scope link
valid_lft forever preferred_lft forever
user@user-Inspiron-518:~$
One network interface called eth0 is enabled up on this system.
To disable down the network interface:
sudo ifconfig interfacename down
eg sudo ifconfig enp0s3 down
Run ip a again to check the status of the network interface and see the word down on the line beginning with the interface name.
To enable up and actvate the network interface:
ifconfig interfacename up
eg ifconfig enp0s3 up
To check that the interface is up:
ip a
When the computer is rebooted, the network will be disabled again.
To keep the network interface up and enabled after rebooting the system, edit the ifcfg-eth0 file default value from onboot=no to onboot=yes.
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.240 # this is /28
IPADDR=192.168.9.1
USERCTL=no
Do not run the systemctl command as it uses the network manager which automatically overrides ifconfig and ip.
Linux usually connects to the internet automatically through an ethernet or wifi connection.
To connect to the internet though ethernet from the command line:
ifconfig
To install ifconfig, install the net-tools package.
To display the status of all interfaces, even those that are down, type the -a option.
ifconf -a
user@user-Inspiron-518:~$ sudo ifconfig -a
[sudo] password for user:
eth0 Link encap:Ethernet HWaddr 00:21:9b:0d:e9:c6
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::221:9bff:fe0d:e9c6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:9577 errors:0 dropped:0 overruns:0 frame:0
TX packets:6534 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9013281 (9.0 MB) TX bytes:1074695 (1.0 MB)
Interrupt:43 Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:523 errors:0 dropped:0 overruns:0 frame:0
TX packets:523 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:50766 (50.7 KB) TX bytes:50766 (50.7 KB)
user@user-Inspiron-518:~$
To how display the configuration of a specific interface:
ifconfig interfacename
To show a short list:
ifconfig -s
To deactivate down an interface:
sudo ifconfig interfacename down
eg sudo ifconfig enp0s3 down
To activate up an ethernet connection device:
sudo ifconfig interfacename up
eg sudo ifconfig enp0s3 up
To check if the ethernet connection is disabled down, run ifconfig without any option. If the connection is down, it will not show on the list.
pete@pete-ID:~$ ifconfig
enp5s3: flags=4163 mtu 1500
inet 192.168.1.102 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::9e09:992b:2386:46c9 prefixlen 64 scopeid 0x20
ether 00:0f:b5:fd:af:f4 txqueuelen 1000 (Ethernet)
RX packets 8094 bytes 7170809 (7.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4863 bytes 522953 (522.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 670 bytes 63345 (63.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 670 bytes 63345 (63.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pete@pete-ID:~$
To troubleshot a network connection, run with the verbose -v option:
ifconfig -v
See errors.
To enable the ARP protocol:
ifconfig interface arp
To disable the ARP protocol:
ifconfig interface -arp
To have the interface accept all incoming packets on the network, for diagnosing network connections or for packet sniffing, turn on promiscuous mode, promisc. Promiscuous mode is off by default.
To check if promisc mode is turned on:
ifconf
If it is on, the word promisc can be found in the output.
To enable the promiscuous mode of an interface:
Type in the right interface name.
sudo ifconfig enp0s3 promisc
To disable the promiscuous mode of an interface:
sudo ifconfig enp0s3 -promisc
Typing the right interface name.
To enable or disable all-multicast mode:
ifconfig interface allmulti
To disable all-multicast mode:
ifconfig interface -allmulti
To set a static IP address:
Do not run any DHCP client program like dhclient or it will conflict with the static address.
sudo ifconfig interfacename ipaddress
eg sudo ifconfig enp0s3 10.0.2.15
To use an alias by assigning another ip address to an interface:
sudo ifconfig interfacename:0 ipaddress
eg sudo ifconfig enp0s3:0 10.0.2.16
More than one address can be assigned to an interface, like
eg sudo ifconfig enp0s3:1 10.0.2.17
That is alias :0 and alias :1
To remove an alias:
sudo ifconfig enp0s3:0 down
Those IP addresses will disappear once the computer is shut down.
To keep the configurations after shutting down, put the commands for assigning multiple IPv4 addresses to one device in a startup script.
To show a single interface:
ifconfig interfacename
eg ifconfig enp0s3
Ifconfig can manage connections on ethernet and wireless interfaces and find information about network devices.
Do not use dhcpcd. Dhcpcd will not install on an old, unsupported distribution of Ubuntu, and is often hard to install anyway. So do not use dhcpcd or dhclient.
pete@pete-ID:~$ dhclient
RTNETLINK answers: Operation not permitted
mkdir: cannot create directory '/run/network': Permission denied
pete@pete-ID:~$ dhcpcd
Command 'dhcpcd' not found, but can be installed with:
sudo apt install dhcpcd5
pete@pete-ID:~$
To install dhcpcd:
user@user-Inspiron-518:~$ sudo apt-get install dhcpcd
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package dhcpcd
user@user-Inspiron-518:~$
Do not use dhcpcd.
Network interfaces can be turned on or off using the ifup and ifdown commands. But an interface that was brought up using ifup and later deconfigured using ifconfig is still recorded as up. So do not use ifup or ifdown.
Names of ethernet cards usually start with enp or eth.
To find the name of the ethernet interface connection adapter:
ip link show | grep "eth"
or
ip link show | grep "enp"
pete@pete-ID:~$ ip link show | grep "enp"
2: enp5s3: mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
pete@pete-ID:~$
pete@pete-ID:~$ ip link show | grep "eth"
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
pete@pete-ID:~$
user@user-Inspiron-518:~$ ip link show | grep eth
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:21:9b:0d:e9:c6 brd ff:ff:ff:ff:ff:ff
user@user-Inspiron-518:~$
Here the ethernet interface is eth0 .
To list show wireless networks:
iwconfig
Note the name of the wireless network interface, like wlan0.
pete@pete-ID:~$ iwconfig
lo no wireless extensions.
enp5s3 no wireless extensions.
pete@pete-ID:~$
To check that the wireless network is up and working:
Type the right name of the interface into this command.
sudo ifconfig interfacename up
eg sudo ifconfig wlan0 up
To turn off a wireless network:
sudo ifconfig interfacename down
pete@pete-ID:~$ sudo ifconfig enp5s3 down
[sudo] password for tom7:
pete@pete-ID:~$
To scan for all the available wireless access points:
sudo iwlist scan | more
That pipe | more command allows scrolling down pages of output.
pete@pete-ID:~$ sudo iwlist scan | more
[sudo] password for tom7:
lo Interface doesn't support scanning.
enp5s3 Interface doesn't support scanning.
pete@pete-ID:~$
user@user-Inspiron-518:~$ sudo iwlist scan | more
[sudo] password for user:
lo Interface doesn't support scanning.
eth0 Interface doesn't support scanning.
user@user-Inspiron-518:~$
The ESSID is the name of the wireless network.
To find an open network: check items that show encryption key set to off.
To find the name of the wireless driver:
wpa_supplicant -help | more
Look for
drivers:
wext = Linux wireless extensions (generic)
nl80211 = Linux nl80211/cfg80211
wired = wpa_supplicant wired Ethernet driver
options:
-b = optional bridge interface name etc
The name of the wireless driver is
nl80211
To connect to the internet, run the wpa_supplicant command:
sudo wpa_supplicant –B -D drivername -i interfacename -c /etc/wpa_supplicant/wpa_supplicant.conf
In this example, the wireless driver is nl80211 and the interface wlan0
sudo wpa_supplicant –B -D nl80211 -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Then to establish networking routing on the local Network:
sudo dhclient
To check the wireless connection to the internet, ping any website.
ping webaddress
user@user-Inspiron-518:~$ ping www.onionmail.org
PING www.onionmail.org (104.26.10.72) 56(84) bytes of data.
64 bytes from 104.26.10.72: icmp_req=1 ttl=60 time=17.0 ms
64 bytes from 104.26.1 etc
To stop ping scanning, press ctrl-c.
^C64 bytes from 104.26.11.72: icmp_req=11 ttl=60 time=16.8 ms
--- onionmail.org ping statistics ---
11 packets transmitted, 11 received, 0% packet loss, time 50364ms
rtt min/avg/max/mdev = 16.142/16.871/17.476/0.388 ms
user@user-Inspiron-518:~$
The wireless network is up, enabled and active.
https://www.computernetworkingnotes.com/linux-tutorials/network-configuration-files-in-linux-explained.html
This file tells where network configuration files are kept in a Linux system and how to edit them with tools to manage a network. You can edit configuration files directly, but you should use configuration tools for editing and updating these files. Using a configuration tool reduces the chances of incorrect editing in configuration files.
All the configuration files are stored in the directory
/etc/sysconfig/network-scripts
The name of each configuration file begins with ifcfg-
To learn about the config files, run the list ls and catalogue cat commands. To edit the files, open them with a text editor like gedit or vi.
To find the config directory:
user@user-Inspiron-518:~$ sudo ls /etc/sysconfig/network-scripts
[sudo] password for user:
ls: cannot access /etc/sysconfig/network-scripts: No such file or directory
user@user-Inspiron-518:~$ sudo ls /etc/sysconfig/
ls: cannot access /etc/sysconfig/: No such file or directory
user@user-Inspiron-518:~$
user@user-Inspiron-518:~$ sudo ls /etc/network/
if-down.d if-post-down.d if-pre-up.d if-up.d interfaces
user@user-Inspiron-518:~$
That may be it.
To view the config settings, run the cat command.
Here are some lines in the sysctrl.conf file about the network.
user@user-Inspiron-518:~$ cat /etc/sysctl.conf
#
pete@pete-ID:~$ cat /etc/sysctl.conf
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3 etc
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3
##############################################################3
# Functions previously found in netbase
#
# Uncomment the next two lines to enable Spoof protection (reverse-path filter)
# Turn on Source Address Verification in all interfaces to
# prevent some spoofing attacks
#net.ipv4.conf.default.rp_filter=1
#net.ipv4.conf.all.rp_filter=1
# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
#net.ipv4.tcp_syncookies=1
# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1
# Uncomment the next line to enable packet forwarding for IPv6
# Enabling this option disables Stateless Address Autoconfiguration
# based on Router Advertisements for this host
#net.ipv6.conf.all.forwarding=1
###################################################################
# Additional settings - these settings can improve the network
# security of the host and prevent against some network attacks
# including spoofing attacks and man in the middle attacks through
# redirection. Some network environments, however, require that these
# settings are disabled so review and enable them as needed.
#
# Do not accept ICMP redirects (prevent MITM attacks)
#net.ipv4.conf.all.accept_redirects = 0
#net.ipv6.conf.all.accept_redirects = 0
# _or_
# Accept ICMP redirects only for gateways listed in our default
# gateway list (enabled by default)
# net.ipv4.conf.all.secure_redirects = 1
#
# Do not send ICMP redirects (we are not a router)
#net.ipv4.conf.all.send_redirects = 0
#
# Do not accept IP source route packets (we are not a router)
#net.ipv4.conf.all.accept_source_route = 0
#net.ipv6.conf.all.accept_source_route = 0
#
# Log Martian Packets
#net.ipv4.conf.all.log_martians = 1
#
user@user-Inspiron-518:~$
There is a network conf file in this sysctl.d directory.
sysctl.d
user@user-Inspiron-518:~$ sudo ls /etc/sysctl.d/
[sudo] password for user:
Sorry, try again.
[sudo] password for user:
10-console-messages.conf 10-ptrace.conf README
10-network-security.conf 10-zeropage.conf
user@user-Inspiron-518:~$
user@user-Inspiron-518:~$ sudo ls /etc/sysctl.d/
10-console-messages.conf 10-ptrace.conf README
10-network-security.conf 10-zeropage.conf
user@user-Inspiron-518:~$ sudo cat /etc/sysctl.d/README
This directory contains settings similar to those found in /etc/sysctl.conf.
In general, files in the 10-*.conf range come from the procps package and
serve as system defaults. Other packages install their files in the
30-*.conf range, to override system defaults. End-users can use 60-*.conf
and above, or use /etc/sysctl.conf directly, which overrides anything in
this directory.
After making any changes, please run "start procps".
user@user-Inspiron-518:~$
user@user-Inspiron-518:~$ sudo ls /etc/sysctl.d/10-network-security.conf
/etc/sysctl.d/10-network-security.conf
user@user-Inspiron-518:~$
Nothing in tht file.
Here is another network file.
user@user-Inspiron-518:~$ sudo cat /etc/networks
# symbolic names for networks, see networks(5) for more information
link-local 169.254.0.0
user@user-Inspiron-518:~$
A link-local address is a network address that is valid only for communications within the network segment or the broadcast domain that the host is connected to. Link-local addresses are not guaranteed to be unique beyond their network segment. So routers do not forward packets with link-local source or destination addresses.
To show the hosts file:
user@user-Inspiron-518:~$ sudo cat /etc/hosts
192.168.1.101 user-Inspiron-518 # Added by NetworkManager
127.0.0.1 localhost.localdomain localhost
::1 user-Inspiron-518 localhost6.localdomain6 localhost6
127.0.1.1 user-Inspiron-518
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
user@user-Inspiron-518:~$
If DNS server is configured in network, do not update the /etc/hosts file. System uses the /etc/hosts file in first place to resolve the IP address. If it finds no entry for a hostname in this file only then will it use the configured DNS server.
To show the host name:
user@user-Inspiron-518:~$ sudo cat /etc/hostname
user-Inspiron-518
user@user-Inspiron-518:~$
That shows the FQDN Fully Qualified Domain Name which includes the hostname and the DNS domain name where the host resides.
Settings stored in the iconfiguration file are applied on the interface when the system is started or the interface is activated.
To test if the network device is active:
ip add show
user@user-Inspiron-518:~$ ip addr show
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:21:9b:0d:e9:c6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.101/24 brd 192.168.1.255 scope global eth0
inet6 fe80::221:9bff:fe0d:e9c6/64 scope link
valid_lft forever preferred_lft forever
user@user-Inspiron-518:~$
It is active. If no output is shown then the network in inactive.
To apply a change to the hostname, restart the system or logout from the current session.
To see the default Linux ARP table:
arp -e
user@user-Inspiron-518:~$ arp -e
Address HWtype HWaddress Flags Mask Iface
192.168.1.1 ether 84:d8:1b:1f:73:99 C eth0
user@user-Inspiron-518:~$
To transfer files on a network or the internet, use the curl command.
To download a file from a web site:
curl -O websiteurl/filename
eg curl –O https://xyz.com/abc.txt
To show a client's ip address, subnet mask, gateway and dns server or to release and renew ip addresses, use dhclient.
To renew an eth0 ip address:
$ sudo dhclient eth0
To lookup server domain names using a DNS Server like CName or MX records, run Domain Information Groper dig.
dig
user@user-Inspiron-518:~$ dig
; <<>> DiG 9.7.1-P2 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27631
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 5
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 420301 IN NS j.root-servers.net.
. 420301 IN NS h.root-servers.net.
. 420301 IN NS a.root-servers.net.
. 420301 IN NS m.root-servers.net.
. 420301 IN NS f.root-servers.net.
. 420301 IN NS i.root-servers.net.
. 420301 IN NS g.root-servers.net.
. 420301 IN NS k.root-servers.net.
. 420301 IN NS b.root-servers.net.
. 420301 IN NS c.root-servers.net.
. 420301 IN NS e.root-servers.net.
. 420301 IN NS d.root-servers.net.
. 420301 IN NS l.root-servers.net.
;; ADDITIONAL SECTION:
a.root-servers.net. 44780 IN A 198.41.0.4
b.root-servers.net. 333891 IN A 199.9.14.201
c.root-servers.net. 410665 IN A 192.33.4.12
f.root-servers.net. 554376 IN A 192.5.5.241
m.root-servers.net. 97386 IN A 202.12.27.33
;; Query time: 30 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Fri Apr 29 17:32:43 2022
;; MSG SIZE rcvd: 308
user@user-Inspiron-518:~$
or
user@user-Inspiron-518:~$ dig postbox22.com
; <<>> DiG 9.7.1-P2 <<>> postbox22.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36735
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0
;; QUESTION SECTION:
;postbox22.com. IN A
;; ANSWER SECTION:
postbox22.com. 10800 IN A 10.1.1.123
;; AUTHORITY SECTION:
postbox22.com. 172800 IN NS ns2.namebrightdns.com.
postbox22.com. 172800 IN NS ns1.namebrightdns.com.
;; Query time: 497 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Fri Apr 29 17:46:37 2022
;; MSG SIZE rcvd: 97
user@user-Inspiron-518:~$
To check the settings of a Network Interface Card NIC, use the ethtool command. This command can be used to configure parameters like speed and duplex.
ethtool is not installed.
$ ethtool eth5
To show information about a domain:
host domainname
user@user-Inspiron-518:~$ host postbox22.com
postbox22.com has address 10.1.1.123
postbox22.com is an alias for service.postbox22.com.
service.postbox22.com is an alias for urlforward.postbox22.com.
urlforward.postbox22.com is an alias for urlforward.postbox22.com.
postbox22.com is an alias for service.postbox22.com.
service.postbox22.com is an alias for urlforward.postbox22.com.
urlforward.postbox22.com is an alias for urlforward.postbox22.com.
user@user-Inspiron-518:~$
To test penetration, a firewall or network, scan a port, traceroute, or show tcp/ip, run hping3. It is not installed.
To show real time system resource statistics:
dstat
user@user-Inspiron-518:~$ dstat
The program 'dstat' is currently not installed. You can install it by typing:
sudo apt-get install dstat
user@user-Inspiron-518:~$
A socket is a hole or slot in the mainboard of a computer where a cable or chip plugs in. A process is the software using the cable and socket. A port is a socket on the outside of the computer for a network or printer cable.
To show information about routing, interface, networking, masqueradeed connections, sockets and so on, run netstat or ss.
To show more statistics run vmstat amd other programs listed below.
user@user-Inspiron-518:~$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 2535020 66808 290216 0 0 10 4 106 529 1 0 98 0
user@user-Inspiron-518:~$
Programs mpstat, iostat and ifstat are not installed.
To connect directly with a remote host, run ftp.
ftp hostaddress
eg ftp 192.168.1.1
To check interface information like ip addresses and mtu values, or change an ip addresses, run ip addr.
To list all the up links:
user@user-Inspiron-518:~$ ip link ls up
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:21:9b:0d:e9:c6 brd ff:ff:ff:ff:ff:ff
user@user-Inspiron-518:~$
To add an ip address to an interface:
ip addr ipnumber dev interfacename
eg sudo ip addr add 10.10.10.1/24 dev eth1
Eth1 is ethernet 1, the interface.
To delete remove an ip address form an interface:
eg sudo ip addr del 10.10.10.1/24 dev eth1
To learn about more network commands, go to
https://ipcisco.com/network-commands-in-linux/
To lookup on the internet information about a website domain name:
whois
user@user-Inspiron-518:~$ whois postbox22.com
Domain Name: POSTBOX22.COM
Registry Domain ID: 2690791154_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.namebright.com
Registrar URL: http://www.NameBright.com
Updated Date: 2022-04-22T06:50:19Z
Creation Date: 2022-04-20T20:20:45Z
Registry Expiry Date: 2023-04-20T20:20:45Z
Registrar: TurnCommerce, Inc. DBA NameBright.com
Registrar IANA ID: 1441
Registrar Abuse Contact Email: support@namebright.com
Registrar Abuse Contact Phone: 17204960020
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
Name Server: NS1.NAMEBRIGHTDNS.COM
Name Server: NS2.NAMEBRIGHTDNS.COM
DNSSEC: unsigned
URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
>>> Last update of whois database: 2022-04-29T08:57:00Z <<<
For more information on Whois status codes, please visit https://icann.org/epp
NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
etc view the registrar's reported date of expiration for this registration.
TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or etc
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.
The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
user@user-Inspiron-518:~$
To setup IP table rules that stop unauthorised access to a network, run an iptables command.
To list the rules for a table:
iptables -L chainname -t tablename
eg iptables -L Chn1 -t Tb1
There the chain name is Chn1 and the table name is Tb1.
To show the bandwidth being used on the network interface:
iftop
To install Iftop:
sudo apt-get install iftop
To enable or disable a network interface, run ifup or ifdown.
ifup interfacename
ifdown inerfacename3
Here in this eg the interface is a router called eth3 and it is being enabled.
eg ifup eth3
To configure a wireless interface:
iwconfig interfacename
eg iwconfig eth0
To check and troubleshoot network connections:
netstat
The netstat command without an option shows open socket information.
With an -r option, it shows routing table information.
netstat -r
To show information about a website domain name:
nslookup
user@user-Inspiron-518:~$ nslookup www.postbox22.com
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
www.postbox22.com canonical name = urlforward.postbox22.com.
urlforward.postbox22.com canonical name = urlforward.postbox22.com.
user@user-Inspiron-518:~$
To show monitor bandwith usage:
nload
Nload is not installed.
To show the bandwidth use of a particular device:
nload devices devicename
eg nload devices eth0
To check open ports on any device and what network services are available:
nmap
Nmap is not installed.
Also see ping command.
To check the IP routing table for routes to destinations:
route
user@user-Inspiron-518:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
user@user-Inspiron-518:~$
To add a route:
eg route add -net 192.168.10.1/24 gw 192.168.1.1
To delete a route:
$ route del -net 192.168.17.1/24 gw 192.168.2.1
SCP copies files from one computer to another computer on the same local network or on a remote network. It can encrypt the files by using Secure Shell SSH. SSH needs to be installed on both the computers. You need to know the username and password of the remote computer system as scp will prompt you for it.
To copy files from a local server to a remote server that is on the local network or a remote network, use scp.
scp -options sourcefilepath desinationfilepath
The source always goes before the destination in the scp command. To send a file from the local computer to a remote computer, type that file as the source. To copy a file from a remote computer to the local computer, that remote file goes first
in the command as the source, followed by the local address as the destination, second.
To copy a file from the current directory to a user on a remote computer:
scp filename.txt username@ipaddress:/home/username/directoryname/filename.txt
user@localhost-ID:~$ cd /home/user/Desktop/
user@localhost-ID:~/Desktop$ sudo scp testscp.txt name@127.0.0.1:/home/name/Desktop/testcp.txt
ssh: connect to host 127.0.0.1 port 22: Connection refused
lost connection
user@localhost-ID:~/Desktop$
If a connection refused error message shows, check that port 22 is open on each computer. SCP uses port 22 by defualt. To check and allow port 22 open for SCP:
user@localhost-ID:~/Desktop$ sudo ufw allow 22
Rule added
Rule added v6
user@localhost-ID:~/Desktop$
user@localhost-ID:~/Desktop$ sudo ufw allow 22
Rule added
Rule added v6
user@localhost-ID:~/Desktop$
Reload ufw to update the new setting.
If an error message shows like connection timed out
lost connection, check that the terminal command line says the current working directory and that the command is typed right.
Commands for scp are much the same as for cp.
To copy files on the local server, use cp.
To copy a file to the desktop of another computer:
Change to directory cd where the file is. Here it is on the desktop of the local computer.
cd ~/Desktop/
user@localhost-ID:~$ cd ~/Desktop/
user@localhost-ID:~/Desktop$
Here the ip address of the source computer is
192.168.1.102/24
user@localhost-ID:~/Desktop$ ifconfig -a
enp5s3 Link encap:Ethernet HWaddr 00:0f:b5:fd:af:f4
inet addr:192.168.1.102
and the ip of the destination is
192.168.1.104/24
sudo scp filename recipient@ipaddrss:/home/recipientname/Desktop/
eg sudo scp testscp.txt name@192.168.1.104:/home/name/Desktop
user@localhost-ID:~/Desktop$ sudo scp testscp.txt name@192.168.1.104:/home/name/Desktop
[sudo] password for user:
ssh: connect to host 192.168.1.104 port 22: Connection timed out
lost connection
user@localhost-ID:~/Desktop$
To check that the SSH port is open through the firewall.
user@localhost-ID:~/Desktop$ sudo ufw status
Status: active
To Action From
-- ------ ----
23/tcp ALLOW Anywhere
To allow network traffic through the ssh port:
user@localhost-ID:~/Desktop$ sudo ufw allow ssh
Skipping adding existing rule
Skipping adding existing rule (v6)
user@localhost-ID:~/Desktop$
SSH is already allowed.
sudo scp testscp.txt name@postbox22:/home/name/Desktop
user@localhost-ID:~/Desktop$ sudo scp testscp.txt name@postbox22:/home/name/Desktop
ssh: Could not resolve hostname postbox22: Name or service not known
lost connection
user@localhost-ID:~/Desktop$
Scp needs the ip address.
That home directory should start with a capital H.
user@localhost-ID:~/Desktop$ sudo scp testscp.txt name92.168.1.104:/Home/name/Desktop
ssh: connect to host 192.168.1.104 port 22: Connection timed out
lost connection
user@localhost-ID:~/Desktop$
Here the sender is on a DHCP connection while the receiver is on a static connection.
To copy a file from a remote computer system to your local computer:
sudo scp remoteusername@remoteipaddress:path/filename.txt
eg sudo scp name@192.168.1.104:~/Home/username/Desktop/filename.txt
To copy a directory with the files in it, type the recursive -r option:
scp -r ~/Desktop/test xyz@:/home/xyz/Desktop
sudo scp -r ~/Desktop/testscp.txt remoteuser@ipaddress:/Home/username/Desktop
There /username/is the name of the directory between /Home/ and /Desktop/
To securely send or receive files and directories between devices over the network, to and from local host and remote host:
scp
eg From local host to remote host:
$ scp $filename user@targethost:remote_path
$ scp myfile.txt ipcisco@192.168.15.1:/xyz/remote_files
$ scp –r /local/my_works/ ipcisco@192.168.15.1:/xyz/directory_1
eg From remote host to local host:
$ scp user@targethost:remote_path local_path
$ scp user@targethost:/file.txt /local/my_files/
$ scp –r user@targethost:/xyz/directory_2 /local/my_works/
To securely transfer files on the network:
sftp
SFTP uses FTP over SSH.
eg $ sftp ipcisco@192.168.5.1
To show details about sockets:
ss
To list listening sockets:
ss -l
user@user-Inspiron-518:~$ ss -l
Recv-Q Send-Q Local Address:Port Peer Address:Port
0 128 127.0.0.1:ipp *:*
0 128 ::1:ipp :::*
0 128 127.0.0.1:9150 *:*
0 128 127.0.0.1:9151 *:*
user@user-Inspiron-518:~$
To show tcp connections only:
ss -t
user@user-Inspiron-518:~$ ss -t
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 127.0.0.1:9151 127.0.0.1:33767
ESTAB 0 0 192.168.1.101:40754 51.83.129.245:https
ESTAB 0 0 127.0.0.1:33762 127.0.0.1:9151
ESTAB 0 0 127.0.0.1:33767 127.0.0.1:9151
ESTAB 0 0 127.0.0.1:33764 127.0.0.1:9151
ESTAB 0 0 127.0.0.1:9151 127.0.0.1:33762
ESTAB 0 0 127.0.0.1:9151 127.0.0.1:33764
user@user-Inspiron-518:~$
To securely connect nodes on the network:
ssh username@ipnumber
or ssh domainname@ipnumber
eg harry@200.200.200.1
To securely connect servers or devices on the network, use ssh or telnet.
To connect to any node on the network using an ip address with or without the port number:
telnet
eg telnet 200.200.200.1
To show TCP transmissions on the network:
tcpdump
To monitor and check the default interfaces of TCP traffic:
sudo tcpdump -i eth0
user@user-Inspiron-518:~$ sudo tcpdump -i eth0
[sudo] password for user:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
08:36:59.450549 IP hiveseed-fin.privex.io.9001 > user-Inspiron-518.50784: Flags [.], seq 3095822116:3095823544, ack 4082861273, win 334, options [nop,nop,TS val 276078116 ecr 1551802], length 1428
08:36:59.450580 IP hiveseed-fin.privex.io.9001 > user-Inspiron-518.50784: Flags [.], seq 1428:2856, ack 1, win 334, options [nop,nop,TS val 276078116 ecr 1551802], length 1428
08:36:59.450590 IP user-Inspiron-518.50784 etc
To stop tcpdump, press ctrl-c.
rtisement, length 32
08:38:57.608375 PPPoE PADI [Service-Name] [Host-Uniq 0x00BB1090]
^C
124 packets captured
692 packets received by filter
568 packets dropped by kernel
user@user-Inspiron-518:~$
To show traffic packets on a network interface:
tshark -i
sudo apt-get install tshark
eg sudo tshark –i eth0
To list show the interface devices:
sudo tshark -D
Tshark is a Wireshark utility.
To list the host series on the way to a destination:
tracepath
eg tracepath www.google.com
user@user-Inspiron-518:~$ tracepath www.postbox22.com
gethostbyname2: Unknown host
user@user-Inspiron-518:~$
To check the nodes on the way from the system to a destination:
traceroute
eg traceroute google.com
sudo apt-get install traceroute
To check system activity:
w
user@user-Inspiron-518:~$ w
09:10:54 up 2:22, 2 users, load average: 0.14, 0.08, 0.08
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user tty7 :0 06:52 2:22m 1:49 0.09s gnome-sessio
user pts/0 :0.0 06:55 0.00s 0.22s 0.00s w
user@user-Inspiron-518:~$
To download the content of a web server or a specific file from the web server:
wget servername/filename
eg wget http://xyz.com/abc.txt
To show information about a domain from the whois database:
whois domainname
user@user-Inspiron-518:~$ whois postbox22.com
Domain Name: POSTBOX22.COM
Registry Domain ID: 2690791154_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.namebright.com
Registrar URL: http://www.NameBright.com
Updated Date: 2022-04-22T06:50:19Z
Creation Date: 2022-04-20T20:20:45Z
Registry Expiry Date: 2023-04-20T20:20:45Z
Registrar: TurnCommerce, Inc. DBA NameBright.com
Registrar IANA ID: 1441
Registrar Abuse Contact Email: support@namebright.com
Registrar Abuse Contact Phone: 17204960020
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
Name Server: NS1.NAMEBRIGHTDNS.COM
Name Server: NS2.NAMEBRIGHTDNS.COM
DNSSEC: unsigned
URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wi
etc The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.
user@user-Inspiron-518:~$
To show the status of the network:
/etc/init.d/networking status
user@user-Inspiron-518:~$ /etc/init.d/networking status
Usage: /etc/init.d/networking {start|stop|restart|force-reload}
user@user-Inspiron-518:~$
The network is not active.
To stop the network:
sudo /etc/init.d/networking stop
Stopping a remote connection can interfere with SSH.
user@user-Inspiron-518:~$ sudo /etc/init.d/networking stop
[sudo] password for user:
* Deconfiguring network interfaces... Ignoring unknown interface eth0=eth0.
[ OK ]
user@user-Inspiron-518:~$
To start the network:
sudo /etc/init.d/networking start
user@user-Inspiron-518:~$ sudo /etc/init.d/networking start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service networking start
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start networking
networking stop/waiting
user@user-Inspiron-518:~$
Run commands manually rather than through the servic(8) utility.
To restart the network or network services:
/etc/init.d/networking restart
user@user-Inspiron-518:~$ sudo /etc/init.d/networking restart
* Reconfiguring network interfaces... [ OK ]
user@user-Inspiron-518:~$
Fedora and Centos use different network commands:
systemctl status network
sudo systemctl start network
sudo systemctl stop network
systemctl restart network
Linux developers prefer to use a command-line interface for configuring a network rather than graphical interface.
To configuring a Linux network on a laptop computer, run netenv, meaning network environment.
netenv
Netenv is a graphic program and does not accept commands from a terminal.
sudo apt-get install netenv
To check whether the Linux network is consistent, and scan how many systems are connected, which ports are open and which services are being run:
nmap
To setup a gateway for systems on the network, first run route.
route
user@user-Inspiron-518:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
user@user-Inspiron-518:~$
Note the gateway address, 192.168.1.1
To scan for a list of connected systems:
nmap -sP gatewaynumber
eg sudo nmap -sP 192.168.1.1
To show information about the open ports, services and connected systems:
sudo nmap -A -O 192.168.x.x
To show the packets being sent between computers:
ettercap
Secure Shell is an encrypted secure version of Telnet and needs a PGP key to authenticate to the remote host.
Systemd-networkd runs in the background on Linux systems and manages ethernet network configurations. It can detect networking devices as they are plugged in and create virtual networking devices.Systemd-networkd does not work if other networking tools are running.
Do not purge or remove systemd. That will crash the whole Linux system.
Systemd is a software suite that provides an array of system components for Linux operating systems.
It manages user processes, provides replacements for various daemons and utilities, including device management, login management, network connection management, and event logging.
The d is for daemon.
Linux jargon
kernel - The kernel is the part of your computer that helps the operating system interact with the hardware.
GNU - is a collection of open-source tools used to develop application programs and operating systems.
distribution, distro - A specific version of the Linux operating system.
desktop environment - a window manager and other applications which help you use the computer.
windows manager - A program used to move and place windows on a computer screen.
terminal - A program used to control the shell of the operating system by typing commands.
root, superuser - The computer user who manages programs on the computer.
root directory - The parent folder that contains all the subdirectories holding programs and files.
package - A program or application. An archive of files used to install and execute or operate a program.
package manager - A program used to add or delete, install or uninstall, programs on the Linux system.
source package - A package of computer program code that a user has to manually compile and install before running the software.
binary package - An executable package of software that is already built and compiled.
execute - Run a program.
repository - A remote computer server storing software packages for downloading.
bootloader - A program that boots and starts a computer operating system.
process - The actions a program performs in the background.
shell - An interface that interprets commands and helps the user run the system.
shell script - A list of commands written into a shell to be activated one after another.
interface - A connection for two or more pieces of hardware.
node - Any system or device connected to a network is also called a node.
domain - A website.
domain name - A unique name that identifies a website.
device - A piece of hardware such as a keyboard, mouse, port, joystick, hard drive, ethernet connection, printer or monitor.
gateway - A gateway is a hardware device that acts as a gate between two networks. It may be a router, firewall, server, or another device that enables traffic to flow in and out of the network.
spoofing - Hiding ones identity or the identity of another user.
catalogue, cat - A list of files, or to list files.
To learn Linux terminology or jargon, browse to:
https://techterms.com
WAN is wide area network
WOL is wake on lan local area network
WiFi is wireless network
Putting a WiFi interface into monitor mode means you can capture packets that other devices are sending to an AP. .and vice versa, if you are using the same frequency and are within range of the other devices. This is a potential security threat and it is probably illegal to intercept other people's packets without their permission.
See wifisudoall.txt.
To check that the ethernet driver is loaded:
user@user-X-ED4:~$ dmesg | grep eth0
[ 2.921365] r8169 0000:03:00.0 eth0: RTL8168d/8111d at 0xffffb6f2807bc000, 6c:f0:49:75:6f:a6, XID 083000c0 IRQ 31
[ 2.921367] r8169 0000:03:00.0 eth0: jumbo features [frames: 9200 bytes, tx checksumming: ko]
[ 2.994678] r8169 0000:03:00.0 enp3s0: renamed from eth0
user@user-X-ED4:~$
To check the status of a wireless network interface:
user-X-ED4:~$ iwconfig
enp3s0 no wireless extensions.
lo no wireless extensions.
user@user-X-ED4:~$
ifconfig - To see information about current network interfaces:
@user-X-ED4:~$ ifconfig
enp3s0 Link encap:Ethernet HWaddr 6c:f0:49:75:6f:a6
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::b4a4:ac0a:9dbf:487f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:895 errors:0 dropped:0 overruns:0 frame:0
TX packets:427 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:812921 (812.9 KB) TX bytes:93855 (93.8 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:177 errors:0 dropped:0 overruns:0 frame:0
TX packets:177 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:13043 (13.0 KB) TX bytes:13043 (13.0 KB)
user@user-X-ED4:~$
To bring up or shut down a network connection, use ifconfig.
route - To adjust the computers network routing table or see through which device packets are sent.
peter@peter-H89U-ED4:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default mygateway.home 0.0.0.0 UG 100 0 0 enp3s0
link-local * 255.255.1.0 U 1000 0 0 enp3s0
191.167.0.0 * 255.255.255.0 U 100 0 0 enp3s0
peter@peter-H89U-ED4:~$
ping - To check whether a system on the network is alive:
S ping IPaddress
Press Ctrl-C to stop ping. Read statistics information.
To test network connectivity by sending a packet to another server and awaiting a reply:
$ ping -c 5 hostname or IP address
The -c option says to count and send the packet 5 times. Otherwise ping will keep sending.
peter@peter-H89U-ED4:~$ ping -c 3 www.aldi.com
PING cdn-t3-au-product.aws.as-worx.com (99.86.213.33) 56(84) bytes of data.
64 bytes from server-99-86-212-33.syd4.r.cloudfront.net (99.86.212.33): icmp_seq=1 ttl=244 time=12.1 ms
64 bytes from server-99-86-212-33.syd4.r.cloudfront.net (99.86.212.33): icmp_seq=2 ttl=244 time=11.6 ms
64 bytes from server-99-86-212-33.syd4.r.cloudfront.net (99.86.212.33): icmp_seq=3 ttl=244 time=9.81 ms
--- cdn-t3-au-product.aws.as-worx.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 9.812/11.226/12.187/1.021 ms
peter@peter-H89U-ED4:~$
Numbers and names in this Linux tutorial document have been changed for privacy.
netstat - To check the status of network interfaces:
netstat -i
e@user-X-ED4:~$ netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
enp3s0 1500 0 1433 0 0 0 649 0 0 0 BMRU
lo 65536 0 177 0 0 0 177 0 0 0 LRU
user@user-X-ED4:~$
To show all active TCP connections:
netstat -t
ne@user-X-ED4:~$ netstat -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 Unknown:59954 static.205.175.76:https ESTABLISHED
user@user-X-ED4:~$
To see all TCP connections, active or ready for Linux to listen to.
e@user-X-ED4:~$ netstat -ta
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 user-X-ED4:domain *:* LISTEN
tcp 0 0 localhost:9050 *:* LISTEN
tcp 0 0 Unknown:59954 static.205.175.76:https ESTABLISHED
user@user-X-ED4:~$
tcpdump - This is a sniffer program. Sniffing is viewing TCP/IP network data packets.
To watch and dump, that means print, headers of data packets, run the command sudo tcpdump. Wait and watch then press ctrl-c to go back to the command prompt.
To capture 1,000 packets in a file called tdout, and try to change IP addresses to names, run:
$ sudo tcpdump -a -c 1000 > tdout
After tcpdump captures the packets, it will quit.
To read the output in the text file called tdout, open it in gedit, or type more tdout.
yne@user-X-ED4:~$ sudo tcpdump -a -c 1000 > tdout
[sudo] password for user:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp3s0, link-type EN10MB (Ethernet), capture size 262144 bytes
....
wait, ctrl-c to go back to the command prompt.
e@user-X-ED4:~$ sudo find / -name tdout
[sudo] password for user:
find: ‘/run/user/1000/gvfs’: Permission denied
/home/user/tdout
user@user-X-ED4:~$
The file tdout is in the /home/user directory.
e@user-X-ED4:~$ sudo gedit /home/user/tdout
See the output and copy and paste it into another text file.
To check whether a program is installed, name it on the command line.
peter@peter-H89U-ED4:~$ traceroute
The program 'traceroute' can be found in the following packages:
* inetutils-traceroute
* traceroute
Try: sudo apt install
To show information about a package, a program and the programs it depends on:
sudo apt-cache show programname
jim@jimGD3:~$ sudo apt-cache show nautilus
[sudo] password for barry:
Package: nautilus
Status: install ok installed
Priority: optional
Section: gnome
Installed-Size: 1660
Maintainer: Ubuntu Desktop Team
Architecture: amd64
Version: 1:3.18.4.is.3.14.3-0ubuntu5
Replaces: nautilus-data (<< 1:3.18.1-1ubuntu1), nautilus-sendto
Depends: libatk1.0-0 (>= 1.32.0), libc6 (>= 2.14), libcairo-gobject2 (>= 1.10.0), libc ... etc.
Library lib files are dependencies of the program.
List all the program packages which are installed on the computer:
sudo apt-cache pkgnames | less
albert@albertUD9:~$ sudo apt-cache pkgnames | less
Press up and down arrows to scroll list.
Press the spacebar to go down from page to page.
Press q to quit the list and make a new command prompt.
To show what lib library dependency files an installed program uses:
ldd
Here the program is called spell and it is in the binary bin directory.
pete@pete-ID:~$ ldd /usr/bin/spell
linux-vdso.so.1 (0x00007ffdf4bad000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000713b60800000)
/lib64/ld-linux-x86-64.so.2 (0x0000713b60a99000)
pete@pete-ID:~$
Ubuntu comes with two package managers, dpkg and apt-get. dpkg can install .deb files on the local computer, but can't download dependencies from the net. While apt-get can download files from the net but not install local .debs. With a local .deb which needs dependencies downloaded from the net, neither tool will work.
The gdebi package manager can process both local and remote packages.
To install the program:
sudo apt install gdebi-core
The gdebi package crashed Synaptic and Software Centre. Neither worked.
To install a deb package using gdebi, run:
sudo gdebi packagename_1.0.deb
passwd - To lock a user's account and stop him from logging in:
sudo passwd -l username
To unlock the account let that user log in again:
sudo passwd -u username
nologin - To shut all users other than root out of the system so that they cannot log in while the system is being fixed:
sudo mkdir /etc/nologin
To let them use the system again:
sudo rm /etc/nologin
That command also stops the other users from logging in with ssh and a command like ssh user@host.
sort - To sort the lines of a list in a text file into alphabetical order:
Run a more command to open and read the text file then run sort. Lines are sorted in order of the first word of each line.
$ sort -f filename.txt
Lines are sorted aphabetically by default. The -f option tells the program to ignore whether a line begins with an upper or lowercase letter.
To sort lines of text numerically:
$ sort -n filename.extension
To check whether a file in the current directory has already been sorted:
sort -c filename.txt
Output tells what is out of order. If there is no output, the file is sorted.
To sort a list of months:
sort -M filename.txt
To sort a list formatted into many k columns in order of the names in column 3:
sort -k 3 filename.txt
To sort a list of items in columns of a .csv file:
Here the items are named in the second column of the file and each column ends with a comma which shows were the next column begins.
sort -k 2 -t , filename.csv
Option -t tells which character marks the end of each item in a column.
mv - To move a file from the current directory to another directory:
The file here is called tdout and is in the /home/user directory.
user@user-X-ED4:~$ mv tdout /home/user/Desktop
The file is moved to the desktop.
user@user-X-ED4:~$ ls /home/user/Desktop
2DO linuxhow1st mirrors tdout
findhow linuxsudob removed18 tdoutcopy
findhow.doc mirrorfail start-tor-browser.desktop ufwfirewall
user@user-X-ED4:~$
TCP/IP is the main protocol of the internet. Each computer in a network has a unique IP address number. The IP number is made up of a number for the host network the computer is on and a number for the client computer itself. The IP addresses of name servers are stored in the file /etc/resolv.conf. IP addresses and host names for the local network and some other systems are in /etc/hosts. Names and IP addresses of networks are in /etc/networks. Instructions on how to translate host names into IP addresses are in /etc/host.conf and /ets/nsswitch.conf.
To look up the IP addresses and host names on the your local network, use more:
user@user-X-ED4:~$ more /etc/hosts
127.0.0.1 localhost
127.0.1.1 user-X-ED4
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
user@user-X-ED4:~$
To find out what a command does, run help.
help commandname
Here the command is called finger.
user@user-X-ED4:~$ help finger
bash: help: no help topics match `finger'. Try `help help' or `man -k finger' or `info finger'.
user@user-X-ED4:~$ man -k finger
nfnl_osf (8) - load and unload os fingerprint database
pinky (1) - lightweight finger
safe_finger (8) - finger client wrapper that protects against nasty stuf...
user@user-X-ED4:~$ info finger
Read information in a text file.
user@user-X-ED4:~$ finger
The program 'finger' is currently not installed. You can install it by typing:
sudo apt install finger
user@user-X-ED4:~$
finger - To find information about users on the internet.
user@user-X-ED4:~$ finger
The program 'finger' is currently not installed. You can install it by typing:
sudo apt install finger
user@user-X-ED4:~$
dirs - To show a list of currently remembered directories:
user@user-X-ED4:~$ dirs
~
user@user-X-ED4:~$
Terminal has been working only in the home ~ directory this session.
To compare an updated file with the old file:
Here the old file is called safe and the updated one safeb. Type a space without any punctuation between file names.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ gedit safe safeb
Both files open at once in Gedit.
diff - To compare files line by line.
gcc - To compile computer programes in C and C++ languages.
make - To choose and recompile source software packages for a program.
less - To show a file page by page:
less filename
user@user-X-ED4:~$ less ~/Desktop/ufwfirewall
Read the text file. To go forward to the next page, press f and to go back a page press b. To quit and go to a new command prompt, press q.
mkdir - To make a new directory or subdirectory.
user@user-X-ED4:~$ mkdir ~/Desktop/testdir
user@user-X-ED4:~$ ls ~/Desktop/
2DO linuxhow1st mirrors tdout ufwfirewall
findhow linuxsudob removed18 tdoutcopy
findhow.doc mirrorfail start-tor-browser.desktop testdir
user@user-X-ED4:~$
rmdir - To delete, erase or remove a directory or subdirectory and the files in it:
rmdir /directoryname
user@user-X-ED4:~$ rmdir ~/Desktop/testdir
apropos - To find online manuals about key words.
$ apropos keyword keyword
user@user-X-ED4:~$ apropos IP address | more
Scroll the piped list of manuals, f forward for next page, b for back a page.
get_myaddress (3) - library routines for remote procedure calls
getaddrinfo (3) - network address and service translation
getaddrinfo_a (3) - asynchronous network address and service translation
getdtablesize (2) - get descriptor table size
getdtablesize (3) - get descriptor table size
getifaddrs (3) - get interface addresses
getipnodebyaddr (3) - get network hostnames and addresses
getipnodebyname (3) - get network hostnames and addresses
getmntent (3) - get filesystem descriptor file entry
getmntent_r (3) - get filesystem descriptor file entry
getnameinfo (3) - address-to-name translation in protocol-independent ma...q
Copy relevant titles and paste them into a text file for reference.
Apropos searches the pages of all the Linux manuals to find the key searchwords.
apropos -a keyword keyword
Use the -a option or put the keywords within quotes.
Options
-a search for more than one word, all these keywords.
-e find words that exactly match the keywords.
-l show a longer description of the command.
In this example here we ask how to send a message to another user of our local network.
$ apropus write
finds too much irrelevant information.
wes7@wes7-ID:~$ apropos -a write message
wall (1) - write a message to all users
write (1) - send a message to another user
write.ul (1) - send a message to another user
wes7@wes7-ID:~$
Searching for those two words finds relevant information.
The program we want is called Write.
To show the manual about the write program, run the man command:
wes7@wes7-ID:~$ man write
WRITE(1) User Commands WRITE(1)
NAME
write - send a message to another user
write user [ttyname]
DESCRIPTION
write allows you to communicate with other users, by copying lines from
your terminal to theirs.
When you run the write command, the user you are writing to gets a
message of the form:
Message from yourname@yourhost on yourtty at hh:mm ... etc
See write tutorial below.
To find a tutorial below about how to use a program:
Here the program is called Write.
With this file called linuxsudo open in gedit text editor, click the three-line icon at top left and select find.
In the blank find field, type $ write.
As gedit does not read quote marks, it sees $ write as two words, searches for the write command below and finds a tutorial about the Write program.
whatis - To find a key word and list online manuals about it. Here the keyword is IP.
@user-X-ED4:~$ whatis IP
ip (7) - Linux IPv4 protocol implementation
ip (8) - show / manipulate routing, devices, policy routing and...
user@user-X-ED4:~$
whereis - To find the directory location of a file such as a binary command program:
whereis commandname
user@user-X-ED4:~$ whereis paste
paste: /usr/bin/paste /usr/share/man/man1/paste.1.gz
user@user-X-ED4:~$
The paste program is in the directory /usr/bin.
id - To show the username and group identity of the current user.
user@user-X-ED4:~$ id
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare)
user@user-X-ED4:~$
To show the identity of another user:
$ id username
groups - To show or print on screen the names of the groups a user is in:
e@ne-945GCM-S2L:~$ groups
username dialout cdrom plugdev lpadmin admin sambashare
That shows the user is an administrator and the only user of the computer and can use the cdrom drive and lp line printer.
w - To check which users are logged in to the system, and what command they are executing, use the command w.
user@user-X-ED4:~$ w
12:16:50 up 3:59, 1 user, load average: 0.35, 0.30, 0.26
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user tty7 :0 08:32 3:59m 3:01 0.16s /sbin/upstart -
user@user-X-ED4:~$
head - To show only the the first three lines at the top head of a file:
user@user-X-ED4:~$ head -3 ~/Desktop/tdout
21:58:10.683812 IP mygateway.home > all-systems.mcast.net: igmp query v3 [max resp time 1.0s]
21:58:10.684975 IP6 fe80::da7d:7fff:fe9d:bf28 > ip6-allnodes: HBH ICMP6, multicast listener query v2 [gaddr ::], length 28
21:58:10.695068 IP6 fe80::b4a4:ac0a:9dbf:487f > ff02::16: HBH ICMP6, multicast listener report v2, 2 group record(s), length 48
user@user-X-ED4:~$
last - To show the last five users who logged in and out of the Linux operating system:
user@user-X-ED4:~$ last | head -5
user tty7 :0 Sun Jun 2 08:32 gone - no logout
reboot system boot 4.8.0-36-generic Sun Jun 2 08:17 still running
wtmp begins Sat Jun 1 17:32:46 2019
user@user-X-ED4:~$
tty - To show the device name of the current computer terminal.
user@user-X-ED4:~$ tty
/dev/pts/0
user@user-X-ED4:~$
whoami - To show the name of the user of the current computer termnal:
user@user-X-ED4:~$ whoami
username
The second line is the output.
file - To find what type a file is and its extension name:
file /direcory/filename
user@user-X-ED4:~$ find ~/Desktop/tdout
/home/user/Desktop/tdout
Ubuntu does not show the extension of plain text files.
stat - To show the status of a file:
user-X-ED4:~$ stat ~/Desktop/tdout
File: '/home/user/Desktop/tdout'
Size: 6756 Blocks: 16 IO Block: 4096 regular file
Device: 801h/2049d Inode: 2105212 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ user) Gid: ( 1000/ user)
Access: 2019-06-01 15:22:04.267704046 +1000
Modify: 2019-05-31 22:16:50.201464899 +1000
Change: 2019-06-01 15:28:59.398351965 +1000
Birth: -
user@user-X-ED4:~$
chmod - change a user's permission to use files and devices.
chown - Change who owns files.
To open the default port 80 through the firewall on each computer of the network:
username@hostname-ID:~$ sudo ufw allow 80
[sudo] password for mick:
Rules updated
Rules updated (v6)
username@hostname-ID:~$
To show who currently is using each computer, run who on each computer:
who
username@hostname-ID:~$ who
mick tty7 2023-12-05 09:19 (:0)
username@hostname-ID:~$
On the other computer is
username@hostname-ID:~$ who
tom7 tty2 2023-12-05 09:19 (:0)
username@hostname-ID:~$
To show the IP address numbers of each computer on the local network:
username@hostname-ID:~$ ip neighbour
192.168.1.1 dev enp1s2 lladdr 84:d8:1b:1f:73:99 STALE
10.42.0.81 dev enp1s5 lladdr 6c:f0:49:75:6f:a6 STALE
fe80::86d8:1bff:fe1f:7399 dev enp1s2 lladdr 84:d8:1b:1f:73:99 router STALE
username@hostname-ID:~$
The neighbourhood network of two computer has these IP addresses
192.168.1.1
10.42.0.81
10.42.0.1
tom7 and mick share the router with IP 192.168.1.1
tom7 has the ip 10.42.0.1 for his system
and mick has 10.42.0.81
passwd - To change a password.
@user-X-ED4:~$ passwd
Changing password for user.
(current) UNIX password:
Follow the password prompts.
fdsk - To see partition information about a hard disk, and to add and removing partitions.
netstat - To check network statistics of the system, pipe a more or head command because netstat shows a long file.
@user-X-ED4:~$ netstat | more
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 Unknown:52758 ns531056.ip-149-5:https ESTABLISHED
tcp 0 0 localhost:9151 localhost:54564 ... etc
Press f or b to scroll and q to quit.
shutdown - To shutdown the computer system:
shutdown -h now
To start Terminal press ctrl-alt-t keys together.
To display or show a list of users on the system:
ls /home
To check the device name of the partition where the Linux root file system is mounted:
user@user-X-ED4:~$ mount | grep ' on / '
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
user@user-X-ED4:~$
fdisk - To check which partition of a hard drive the operating sytem is running on:
sudo fdisk -l /dev/sda
user@user-X-ED4:~$ sudo fdisk -l /dev/sda
[sudo] password for user:
Sorry, try again.
[sudo] password for user:
Disk /dev/sda: 117.4 GiB, 126034206208 bytes, 246160559 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc7f51bf9
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 241977343 241975296 115.4G 83 Linux
/dev/sda2 241979390 246159359 4179970 2G 5 Extended
/dev/sda5 241979392 246159359 4179968 2G 82 Linux swap / Solaris
user@user-X-ED4:~$
So Linux is on device named /dev/sda1.
cut - To cut parts out of lines of a file use a cut command.
To cut the first 10 characters -c out of each line of a list and print the shortened list to a file:
cut -c numbercharacters filename
$ cut -c 1-10 filename.txt
To first see the file uncut, this file being called testlist:
user@user-Z-ED4:~$ cd ~/Desktop
user@user-Z-ED4:~/Desktop$ cat testlist
List test
Apples are good.
Oranges are juicy.
Bananas taste nice when soft when ripe.
Melons are refreshing.
Lemons and limes are bitter.
user@user-Z-ED4:~/Desktop$ cut -c 1-10 testlist
List test
Apples are
Oranges ar
Bananas ta
Melons are
Lemons and
user@user-Z-ED4:~/Desktop$
To cut some columns of text out of a formatted .csv file or other text file, show a character which delimits -d each column. Here the character between each column is , a comma. Show with an option -f which columns or fields are to be cut, second and third columns or whatever.
cut -d ',' -f 1,5 filename.csv
Here the filename is listtest.
user@user-Z-ED4:~/Desktop$ cat listtest
Daniel,Johns,21,Manchester
Vincent,Smith,44,London
Brian,Arthur,32,Newport
Harrold,Adams,52,Brighton
user@user-Z-ED4:~/Desktop$ cut -d ',' -f 2,3 listtest
Johns,21
Smith,44
Arthur,32
Adams,52
user@user-Z-ED4:~/Desktop$
Or after the filename above, add the extension such as .csv, listtest.csv.
Run the command cat filename again to see that the original files remain uncut.
To copy the output of a command into a new text file:
command > newfilename.txt
Here the commandf is to list what is in the directory called /bin and save the list in a file called binlist.txt
ls -l /bin > binalist.txt
The new file will overwrite an old file with the same name if there is one.
To see the contents of new file, use the cat or more command as follows:
cat binalist.txt
user@user-Z-ED4:~/Desktop$ cut -d ',' -f 2,3 listtest > listcut.txt
user@user-Z-ED4:~/Desktop$
There the file called listtest is cut and the output is saved as a file called listcut. The > new file is saved into the same directory as the original file is in. So usually give the new file a different name so that it does not overwrite the old.
user@user-Z-ED4:~/Desktop$ cat listcut.txt
Johns,21
Smith,44
Arthur,32
Adams,52
user@user-Z-ED4:~/Desktop$
join - To join two lists from different files and save the joined list in a new file, use the join and > commands.
First sort the two list files so that the items listed in one file match up with the items in the other, line by line. Then run:
join filename1.txt filename2.txt > joinedfile.txt
sort -f testlistk > testlistk2
sort -f testlist > testlist2
The 2s stop the new files from overwriting the old.
That sorts the file into alphabetical order by default.
join testlist testlistk > fruitsale
user@user-Z-ED4:~$ cd ~/Desktop
user@user-Z-ED4:~/Desktop$ sort -f testlistk > testlistk2
user@user-Z-ED4:~/Desktop$ sort -f testlistk > testlistk2; sort -f testlist > testlist2
user@user-Z-ED4:~/Desktop$
user@user-Z-ED4:~/Desktop$ cat testlist2 testlistk2
Apples are crisp.
Bananas taste nice when soft when ripe.
Lemons and limes are bitter.
List fruit
Melons are refreshing.
Oranges are juicy.
-
Apples $4
Bananas $1
Fruit prices a kilo
Lemons $3
Melons $3
Oranges $2
user@user-Z-ED4:~/Desktop$
Now join testlist testlistk > fruitsale
user@user-Z-ED4:~/Desktop$ join testlist2 testlistk2 > fruitsale
user@user-Z-ED4:~/Desktop$
Remove the heading line from each file because it does not match anything.
Check that each item in one file is on the same line space as the same item in the other file.
user@user-Z-ED4:~/Desktop$ cat fruitsale
Apples are crisp. $4
Bananas taste nice when soft when ripe. $1
Lemons and limes are bitter. $3
Melons are refreshing. $3
Oranges are juicy. $2
user@user-Z-ED4:~/Desktop$
Among options for the join command are -ia for ignore case and show unpaired items.
diff - To show the difference between two files:
diff file1.txt file2.txt
@user-Z-ED4:~/Desktop$ diff fruitsale fruitsale2
6c6
< Lemons and limes are bitter. $3
---
> Lemons and limes are bitter. $2
user@user-Z-ED4:~/Desktop$
The price is different. The command usually needs the file extension.
To compare two directories:
diff dir1 dir2
@user-Z-ED4:~/Desktop$ diff testfold ~/Downloads/testfold
Only in testfold: tdoutcopy
user@user-Z-ED4:~/Desktop$
A file called tdoutcopy is not in the second directory of the same name.
Diff gives no output if the files or directories compared are the same as each other.
cmp - To compare two files byte by byte and show the number of any line where a byte is different:
cmp file1.txt file2.txt
If no differences are found, cmo by default returns no output.
lp - To print a file to the default printer:
lp filename
or lpr filename
To print to another printer than the default:
lp -d printername filename
or lpr -P printer filename
To print the output of a program:
program | lp
program | lp -d printername
or program | lpr
program| | lpr -P printername
> - To redirect the output from a command to a file other than the screen, use the > character.
To print the contents of a text file on line printer named /dev/lp0:
$ cat testfile.txt > /dev/lp0
To show the printer devices and drivers on a system:
lpinfo
lpr - To print a file on paper, run the cat and > commands to the printer. Here the line printer device is called lp.
sudo cat filename.txt > /dev/lp
To print using the lpr command instead of the lp command, use the -P option:
lpr -P printer filename
To show a list of printers -p with the -d default printer:
lpstat -p -d
user@user-Z-ED4:~$ lpstat -p -r
printer WorkCentre-3119-Series is idle. enabled since Fri 03 May 2019 01:50:47 PM PGT
scheduler is running
user@user-Z-ED4:~$
A printer might be called laserjetV for example or this one might be named WorkCentre-3119-Series or WorkCentre 3119.
lpadmin - To manage printers:
user@user-Z-ED4:~$ sudo lpadmin
Usage:
lpadmin [-h server] -d destination
lpadmin [-h server] -x destination
lpadmin [-h server] -p printer [-c add-class] [-i interface] [-m model]
[-r remove-class] [-v device] [-D description]
[-P ppd-file] [-o name=value]
[-u allow:user,user] [-u deny:user,user]
user@user-Z-ED4:~$
lp - To print what you type or copy into Terminal as standard output, type a hyphen - before a new file name in the lp command.
lp -d printername -newfilename
lp -dc printername -o media=a4 -o n 1 -newfilename
That says print one copy on a4 size paper. The c is for backward compatibility.
Type ctrl-v to paste text from another file into Terminal.
Type two hyphens -- to mark the end of the text to be printed direct from Terminal.
To cancel all print jobs:
cancel a
To cancel a printer job:
cancel job-id
To show the id number of a print job:
lpstat
In this command example, the first hash # marks the end of the sudo command prompt for the superuser or administator, and the second -# is part of the command which means to print 2 or another number of copies.
# lpr –P laserjetV –#2 /home/user1/file1
Command lp uses n instead of #.
Commands can be joined or combined on a command line by semicolons ; so that each command runs independently. The pipe | sends the output of one command to be the input for another command.
To substitute one group of characters for another throughut a text file, use tr command. To convert a DOS text file to a Linux text file, delete extra carriage returns:
tr -d '\015' < filename.dos > filename.linux
Here the -d option means delete and the '\015' code means a carriage return character.
To count the number of lines, words and characters in a text file, use a word count wc command. Here the file is called findhow.
user@user-X-ED4:~$ wc ~/Desktop/findhow
260 1170 6545 /home/user/Desktop/findhow
user@user-X-ED4:~$
To compress a file:
compress
To decompress a file:
uncompress
To show the amount of free and used memory in the system:
user@user-X-ED4:~$ free
total used free shared buff/cache available
Mem: 4041136 576428 2922252 12652 542456 3198364
Swap: 2089980 0 2089980
user@user-X-ED4:~$
Hyphens typed near commands in this file mean nothing and are not part of the command.
halt - To shut down Linux and halt stop turn off the computer, type the command halt.
reboot - To stop Linux and restart reboot the computer.
shutdown = To shut down Linux.
ps - To show a list of command processes running:
user@user-X-ED4:~$ ps
PID TTY TIME CMD
2346 pts/1 00:00:00 bash
2446 pts/1 00:00:00 ps
user@user-X-ED4:~$
kill - To close a stalled program first run the ps ax command to find the number of the stalled program then use the kill command.
user@user-X-ED4:~$ ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:01 /sbin/init splash
2 ? S 0:00 [kthreadd]
3 ? S 0:00 [ksoftirqd/0]
4 ? S 0:00 [kworker/0:0]
5 ? S< 0:00 [kworker/0:0H]
7 ? S 0:00 [rcu_sched]
8 ? S 0:00 [rcu_bh]
9 ? S 0:00 [migration/0]
10 ? S< 0:00 [lru-add-drain]
etc
The process ID numbers are in the the PID first column. An S in the Stat status column says the process is sleeping, an R says the proces is running. To kill a stalled process run
kill processnumber
ldd - To show what shared libraries are needed to run a program:
uname - To show all the information about the system and the Linux kernel:
user@user-X-ED4:~$ uname -a
Linux user-X-ED4 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
user@user-X-ED4:~$
groups - To show a list of groups that include a specified user:
user@user-X-ED4:~$ groups
user adm cdrom sudo dip plugdev lpadmin sambashare
user@user-X-ED4:~$ groups user
user : user adm cdrom sudo dip plugdev lpadmin sambashare
user@user-X-ED4:~$
id - To show the user and group ID identity for a specific user.
is username
user@user-X-ED4:~$ id user
uid=1000(user) gid=1000(user) groups=1000(user),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare)
user@user-X-ED4:~$
su - To start a command shell for root administrator:
$ su
To start a command shell for another user:
su username
df - To show display free and available space in all mounted storage devices:
user@user-X-ED4:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1999368 0 1999368 0% /dev
tmpfs 404116 6596 397520 2% /run
/dev/sda1 118956292 6138204 106752324 6% /
tmpfs 2020568 256 2020312 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 2020568 0 2020568 0% /sys/fs/cgroup
tmpfs 404116 64 404052 1% /run/user/1000
/dev/sdb1 301486576 201799452 84349448 71% /media/user/185ce059-d153-44dc-9eb9-d4737f5c0692
user@user-X-ED4:~$
du - To show disk use information:
user@user-X-ED4:~$ $ du | more
5932 ./Backupdesk/home/user/Desktop/Allianz
6748 ./Backupdesk/home/user/Desktop
6752 ./Backupdesk/home/user
6756 ./Backupdesk/home
... etc
Press q to quit and go back to a command prompt.
-fdformat - To format a floppy disk.
fdformat options devicename
Formatting removes all files from a disk. Floppies formatted for one operating system may not mount for other systems or other distributions or versions of Linux. Standard factory-default formatting is called FAT. With non-standard formatting, a Linux command needs an extra parameter.
Fdformat may not work on a fd device /dev/fd0 that is not auto-detected by the operating system.
To show more about non-standard device names:
man fdfloppy.
-setfd To load and show the parameters of the floppy disk, run
setfdprm
Setfdprm loads parameters for auto-detecting different floppy devices. This program is part of Fdutils which is not installed by default with Ubuntu16.
user@user-ID:~$ sudo apt install fdutils
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
fdutils ...etc...
Setting up fdutils (5.5-20060227-7) ...
user@user-ID:~$
user@user-ID:~$ setfdprm --help
Usage: setfdprm [-c] [-p] [-y] [-n] drive [geometry]
-c --clear clear the geometry parameters
-p --permanent set the geometry parameters permanently
-y --message-on switch messages on
-n --message-off switch messages off
Run setfd each time you put a different floppy into the drive.
To load parameters for a different floppy disk:
Change the following numbers to match the disk. Here a standard MSDOS formatted floppy disks has 80 tracks cyl, 2 sides and 18 sectors a track. It is usually IBM formatted, 3.5 inch, 1.44MB, that is 1474560 bytes total capacity and 2HD high density. For 1.44, try typing 1.4 or 1440, /dev/fd0H1440, and try 2hd or hd.
setfdprm /dev/fd0 sect=10 hd ssize=1024 cyl=80
That command temporarily reprograms the floppy controller.
To read and copy the contents of a floppy disk into an image file after running setfdprm:
cat /dev/fd0 >filename
To format the floppy disk:
superformat /dev/fd0 sect=10 hd ssize=1024 cyl=80
Change numbers to match the disk, for example Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Superformat is part of fdutils.
To format a 3.5inch floppy disk, unmount it, format it, make a file system on it and mount it.
Check the disk to see that one of its square holes is shut. Insert the disk in the drive bay. Floppy devices are usually called /dev/fd0 and mounted at /media/floppy0 for Ubuntu.
user@user-ID:/media/floppy0$ ls
user@user-ID:/media/floppy0$
List shows that the floppy is not mounted.
If it needs to be unmounted, run
umount /dev/fd0
user@user-ID:/media/floppy0$ fdformat /dev/fd0
fdformat: cannot access file /dev/fd0: Permission denied
user@user-ID:/media/floppy0$ sudo fdformat /dev/fd0
[sudo] password for user:
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting ... done1
Verifying ... Problem reading track/head 41/1, expected 9216, read 5120
user@user-ID:/media/floppy0$
Wait until fdformat is done. Here there is a problem reading part of the old disk.
To make a file system on the floppy:
mkfs /dev/fd0
user@user-ID:/media/floppy0$ sudo mkfs /dev/fd0
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 1440 1k blocks and 184 inodes
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
user@user-ID:/media/floppy0$
To make a fat filing system on a floppy disk:
mkfs.vfat /dev/fd0
Or for an extension2 system, mkfs.ext2
user@user-ID:/media/floppy0$ sudo mkfs.vfat /dev/fd0
[sudo] password for user:
mkfs.fat 3.0.28 (2015-05-16)
user@user-ID:/media/floppy0
If a disk cannot be formatted, try editing fstab using nano. It might be a non-standard formatting error. If a floppy disk is damaged, it might have to be broken apart and tossed in the bin.
To show user permissions for a floppy disk:
user@user-ID:/media/floppy0$ ls -al /media/floppy0
total 11
drwxrwxr-x 2 user user 7168 tom 1 1970 .
drwxr-xr-x 4 root root 4096 Aug 28 13:23 ..
user@user-ID:/media/floppy0$
To unmount a floppy disk:
user@user-ID:/media/floppy0$ umount /dev/fd0
umount: /dev/fd0: not mounted
user@user-ID:/media/floppy0$
When the light goes out on the drive bay, press the button and remove the disk.
To copy files to a newly formatted floppy disk:
user@user-ID:/media/floppy0$ sudo cp ~/Desktop/*JPG /media/floppy0
user@user-ID:/media/floppy0$ ls
LOZZZGO2C.JPG nORE009.JPG SAZZMPLE01.JPG
nCOVER19LG.JPG SUMCCPLE02.JPG
user@user-ID:/media/floppy0$
To remove old files from a floppy disk without formatting it:
user@user-ID:~$ cd /media/floppy0/
user@user-ID:/media/floppy0$ ls
p2p.txt radio.txt telnetlis.txt sudofloppy telnet.txt youtube.txt
user@user-ID:/media/floppy0$
user@user-ID:/media/floppy0$ sudo rm /media/floppy0/*
user@user-ID:/media/floppy0$ ls
user@user-ID:/media/floppy0$
All files were removed from the floppy.
To see who has permission to format a floppy:
user@user-ID:/media/floppy0$ ls -al /dev/fd0
brw-rw---- 1 root disk 2, 0 Sep 11 15:50 /dev/fd0
That says that b the block device can be read and written to by the root user owner of the files and by users in his group but not by other users.
To show and see who has permission to use a floppy disk:
user@user-ID:~$ ls -al /media/floppy0
total 8
drwxrwxr-x 2 root root 4096 Aug 28 03:13 .
drwxr-xr-x 4 root root 4096 Aug 28 13:23 ..
user@user-ID:~$
fsck - To check and repair a file system
@user-X-ED4:~$ fsck -pc
tty - Show the device name for the current terminal.
@user-X-ED4:~$ tty
/dev/pts/18
user@user-X-ED4:~$
To check and mount a partition of a hard drive:
Here the partition is a new swap partiton which is not listed in the /etc/fstab/ directory.
user:~$ mount /dev/disk/by-id/
mount: can't find /dev/disk/by-id in /etc/fstab
user:~$ ls /dev/disk/by-id/
ata-HL-DT-ST_DVDRAM_GH22NS50_K3BA3215831
ata-IC35L060AVV207-0_VNVB02G2CHGGYV
ata-IC35L060AVV207-0_VNVB02G2CHGGYV-part1
ata-IC35L060AVV207-0_VNVB02G2CHGGYV-part2
ata-IC35L060AVV207-0_VNVB02G2CHGGYV-part5
ata-SanDisk_SDSSDP128G_151083403719
ata-SanDisk_SDSSDP128G_151083403719-part1
ata-SanDisk_SDSSDP128G_151083403719-part2
ata-SanDisk_SDSSDP128G_151083403719-part3
ata-ST340014A_3JX6EHF2
ata-ST340014A_3JX6EHF2-part1
ata-ST340014A_3JX6EHF2-part2
ata-ST340014A_3JX6EHF2-part5
ata-WDC_WD3200AAKS-00B3A0_WD-WCAT15383573
ata-WDC_WD3200AAKS-00B3A0_WD-WCAT15383573-part1
ata-WDC_WD3200AAKS-00B3A0_WD-WCAT15383573-part2
ata-WDC_WD3200AAKS-00B3A0_WD-WCAT15383573-part5
wwn-0x5001480000000000
wwn-0x50014ee156bf6365
wwn-0x50014ee156bf6365-part1
wwn-0x50014ee156bf6365-part2
wwn-0x50014ee156bf6365-part5
wwn-0x5001b44e38dac5c7
wwn-0x5001b44e38dac5c7-part1
wwn-0x5001b44e38dac5c7-part2
wwn-0x5001b44e38dac5c7-part3
user:~$ ls /media
floppy floppy0 user
user:~$ ls /media/user/
user:~$ cd /
user:/$ mount /dev/disk/by-id/
mount: can't find /dev/disk/by-id in /etc/fstab
user:/$ ls /mnt/wwn-0x5001b44e38dac5c7-part2
user:/$ mount /mnt/wwn-0x5001b44e38dac5c7-part2
mount: only root can mount /dev/disk/by-id/wwn-0x5001b44e38dac5c7-part2 on /mnt/wwn-0x5001b44e38dac5c7-part2
user:/$ sudo mount /mnt/wwn-0x5001b44e38dac5c7-part2
[sudo] password for user:
mount: unknown filesystem type 'swap'
user:/$
A swap partition can be activated in Drives selecting the swap partition then clicking the triangle button.
-mkswap To make a swap space for Linux in a partition of a hard drive.
user@user-X-ED4:~$ mkswap --help
Usage: mkswap [options] device [size]
Set up a Linux swap area.
Options:
-c, --check check bad blocks before creating the swap area
-f, --force allow swap size area be larger than device
-p, --pagesize SIZE specify page size in bytes
-L, --label LABEL specify label
-v, --swapversion NUM specify swap-space version number
-U, --uuid UUID specify the uuid to use
-V, --version output version information and exit
-h, --help display this help and exit
user@user-X-ED4:~$
swapoff - To deactivate and turn off a swap space.
swapon - To activate and turn on a swap space.
gcc - To develop or compile Linux software in languages C, C++ or Objective-C.
D3:~$ gcc --help
Usage: gcc [options] file...
Options:
-pass-exit-codes Exit with highest error code from a phase
--help Display this information
--target-help Display target specific command line options
To configure a network connection, understand the following jargon:
DNS - a domain name server on the internet looks up IP internet protocol addresses and translates them into their hostnames.
DHCP - is host protocol which helps configure a connection between one computer on a network and another. To use DHCP, open a network configuration program and at the BOOTPROTO prompt, select dhcp instead of static.
Ethernet - a wired network with a device name of etho0 or etho another number and its transmission speed measured in megabits a second, Mnps.
Hostname - a word naming an IP internet protocol address number.
Internet - an internet is a network of computer networks.
IP address - the internet protocol number of a computer on an internet, which can be IPv6 for 16 bytes or IPv4 for 4 bytes.
Netmask - a network mask is another number which defines an IP address.
Router - a gateway hardware device which connects two networks or connects a computer to the internet.
TCP/IP - transmission protocol standards for network communications software.
Wi-Fi - wireless networking known as IEEE 802.11. The name of a wifi defice is w1an0 or w1an and another number.
Here are examples of settings to input for graphic programs which connect to networks. Most of these are usually set automatically by the software.
Wireless disconnected hardware address 00:25:86:85:27:83
Wireless security WPA and WPA2 personal.
Wireless connected hardware address 00:26:5B:26:A8:56
Speed 100 Mbps
IP address 173.24.21.11
Subnet mask 255.255.255.0
Default route 172.34.21.1
DNS 172.34.21.1
Connection name System em1
IPv4 settings, Method Manual, Address 172.24.21.11 , Netmask 255.255.255.1, Gateway 172.24.21.3
Tick Require IPv4 addressing for this connection to complete.
get - To find the public internet protocol IP address which websites and web services see when you access them from your computer:
Press the Ctrl-Alt-Del keys together and press t.
At the Terminal command prompt, type
user@user-Z-ED4:~$ dig +short myip.opendns.com @resolver1.opendns.com
220.239.254.183
user@user-Z-ED4:~$
That is your public IP address.
Or
wget - To check options of the wget program, run help.
user@user-Z-ED4:~$ wget --help
GNU Wget 1.17.1, a non-interactive network retriever.
Usage: wget [OPTION]... [URL]...
Mandatory arguments to long options are mandatory for short options too.
Startup:
-V, --version display the version of Wget and exit
-h, --help print this help
.... etc
Click and drag scroll bar at right in Terminal.
Options q and o tell wget to quietly output log messages to a file. Option capital O says to write a document to a file. The url address tells where wget is to find the document.
user@user-Z-ED4:~$ wget -qO https:api.ipify.org
Or
user@user-Z-ED4:~$ dig -h
Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}
{global-d-opt} host [@local-server] {local-d-opt}
[ host [@local-server] {local-d-opt} [...]]
Where: domain is in the Domain Name System
q-class is one of (in,hs,ch,...) [default: in]
... etc
hostname - To find show your computer's IP address:
hostname -I
user@user-Z-ED4:~$ hostname -I
183.152.0.2
user@user-Z-ED4:~$
That is a sample address and is not real.
dig
ifconfig - To find the private inernet protocol IP address of your computer within your network:
Press the Ctrl-Alt-t keys together.
At the Terminal command prompt, type
ifconfig
and press enter.
user@user-Z-ED4:~$ ifconfig
enp3s0 Link encap:Ethernet HWaddr 6c:f0:49:75:6f:a6
inet addr:183.152.0.2 Bcast:183.1838.0.24 Mask:256.256.256.0
inet6 addr: fe80::a4a4:bc0a:7dbf:496f/34 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4278 errors:0 dropped:0 overruns:0 frame:0
TX packets:3112 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1334204 (1.3 MB) TX bytes:334216 (334.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:277 errors:0 dropped:0 overruns:0 frame:0
TX packets:277 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:20896 (20.8 KB) TX bytes:20896 (20.8 KB)
user@user-Z-ED4:~$
The IP address of your computer on the current network here is inet addr:183.152.0.2
Or enter this command.
ip addr
user@user-Z-ED4:~$ ip addr
1: lo: mtu 6436 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp3s0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 6c:f0:49:75:6f:a6 brd ff:ff:ff:ff:ff:ff
inet 183.152.0.2 brd 183.1838.0.24 scope global dynamic enp3s0
valid_lft 77107sec preferred_lft 77107sec
inet6 fe80::b4a4:ac0a:9dbf:487f/64 scope link
valid_lft forever preferred_lft forever
user@user-Z-ED4:~$
Or enter this command without a hyphen
ip a
user@user-Z-ED4:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp3s0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 6c:f0:49:75:6f:a6 brd ff:ff:ff:ff:ff:ff
inet 183.152.0.2 brd 183.1838.0.24 scope global dynamic enp3s0
valid_lft 76868sec preferred_lft 76868sec
inet6 fe80::b4a4:ac0a:9dbf:487f/64 scope link
valid_lft forever preferred_lft forever
user@user-Z-ED4:~$
The sample IP numbers above are not real. For your security, do not give your computer's public IP address number to anybody.
To find the IP addresses of DNS servers, the computer's internet domain name and other domains, look in this folder: /etc/resolv.conf
peter@peter-H89U-ED4:~$ less /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 125.0.3.1
search home
Press q to go back to the command prompt.
To test the network connection, run utility programs like route, ping, traceroute, host and netstat.
host - To look up the number of a host server:
host serveraddress
peter@peter-H89U-ED4:~$ host www.otnet.com
www.optnet.com has address 211.28.132.105
peter@peter-H89U-ED4:~$
netstat - To show information about the network interface:
netstate -i
peter@peter-H89U-ED4:~$ netstat -i
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
enp3s0 1500 0 755 0 0 0 492 0 0 0 BMRU
lo 65536 0 200 0 0 0 200 0 0 0 LRU
peter@peter-H89U-ED4:~$
enp3s0, lo, em1 and eth1 are the names of network devices.
To show information about open ports and the systems to which they are connected:
peter@peter-H89U-ED4:~$ netstat | less
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 peter-H89U-ED4:54092 onion.raccoonsocie:9001 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 21805 /run/user/1000/system
d/notify
unix 3 [ ] DGRAM 12387 /run/systemd/notify
unix 7 [ ] DGRAM 13382 /run/systemd/journal/
socket
unix 2 [ ] DGRAM 13387 /run/systemd/journal/
syslog
unix 16 [ ] DGRAM 13390 /run/systemd/journal/
dev-log
unix 3 [ ] STREAM CONNECTED 29107
unix 3 [ ] STREAM CONNECTED 17745 /var/run/dbus/system_
bus_socket ... etc
Press arrow keys to scroll and q to quit.
To show all ports connected, listening or not:
peter@peter-H89U-ED4:~$ netstat -a | less
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 peter-H89U-ED4:domain *:* LISTEN
tcp 0 0 localhost:9050 *:* LISTEN
udp 0 0 *:ipp *:*
udp 0 0 *:mdns *:*
etc ...
udp6 0 0 [::]:50630 [::]:*
raw6 0 0 [::]:ipv6-icmp [::]:* 7
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 21805 /run/user/1000/system
d/notify
unix 2 [ ACC ] STREAM LISTENING 21806 /run/user/1000/system
d/private
unix 2 [ ACC ] SEQPACKET LISTENING 13380 /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 22154 @/tmp/.ICE-unix/1856
... etc
unix 2 [ ACC ] STREAM LISTENING 24588 @/tmp/dbus-5ONqAy9IQ2
unix 3 [ ] DGRAM 12387 /run/systemd/notify
unix 2 [ ACC ] STREAM LISTENING 12388 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 13381 /run/systemd/journal/stdout
unix 7 [ ] DGRAM 13382 /run/systemd/journal/socket
unix 2 [ ACC ] STREAM LISTENING 13383 /run/systemd/fsck.progr
To display network statistics, use the -s option:
peter@peter-H89U-ED4:~$ netstat -s | less
Ip:
698 total packets received
1 with invalid addresses
638 requests sent out
40 outgoing packets dropped
13 dropped because of missing route
Icmp:
80 ICMP messages received
0 input ICMP message failed.
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 81
IcmpMsg:
InType3: 80
OutType3: 81
Tcp:
6 active connections openings
: ... etc
Type pipe | less after netstat commands so you can scroll or turn the pages.
To show which programs are using network connections:
peter@peter-H89U-ED4:~$ netstat -p | less
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
PID/Program name
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node PID/Program name P
ath
unix 2 [ ] DGRAM 21805 1539/systemd /
run/user/1000/systemd/notify
unix 3 [ ] DGRAM 12387 - /
run/systemd/notify
unix 7 [ ] DGRAM 13382 - /
run/systemd/journal/socket
unix 2 [ ] DGRAM 13387 - /
nix 3 [ ] STREAM CONNECTED 116595 2569/gnome-terminal
unix 3 [ ] STREAM CONNECTED 22044 1893/indicator-mess
unix 3 [ ] STREAM CONNECTED 22989 - @
unix 3 [ ] STREAM CONNECTED 22072 1705/dbus-daemon @/tmp/dbus-5ONqAy9IQ2
unix 3 [ ] STREAM CONNECTED 17862 -
unix 3 [ ] STREAM CONNECTED 22296 2064/gvfs-afc-volum
unix 3 [ ] STREAM CONNECTED 23182 2038/gvfs-udisks2-v
u ... etc
Press q to quit.
A deleted file can be recovered until it is overwritten by other data. The shred command helps prevent the recovery of deleted files in Linux by overwriting them with random data.
To shred a file:
shred options filename
If there is a space in the file name, put quotation marks around the whole file name.
Options -n 6 -u -z
-n number of times to overwrite the file
-u overwrite and delete the file
-z overwrite the shredded file with zeros
Here the file is called spud and it is in the directory called Desktop.
shred -n6 -uz ~/directory/filename
user&host-id:~$ shred -n6 -uz ~/Desktop/spud
user&host-id:~$
To shred a file in the same directory without options:
shred filename
Be sure to type the name of the file as it is written in file manager. Here the file called secants has a .jpg ending. Plain text files are listed in file manager without any endings, suffix.
user&host-id:~/Desktop$ shred secants.jpg
user&host-id:~/Desktop$
To show the contents of a shredded file:
cat filename
user:~$ cat ~/Desktop/spud
cat: /home/sue7/Desktop/spud: No such file or directory
user&host-id:~$
Spud has been overwritten and deleted.
This is what the image file called secants looks like shredded.
user&host-id:~/Desktop$ cat secants.jpg
���[����@���,1up-�M N��AMt��c2<�&��ܳ�'�8Q�a��l�~����o0�����E`��(�쮟Sns�詶Z- {��^L|_���s��,zE��8�^��ɸ�Ub���h�Mb��]��V �YZ�����rώ�K�2-ώ�˺C+�t��(�UrY�a�J�!�7�q/f;�(����/���\#��
[�5ީj
x� a^�+�~�����g���B�����r������E��cu� etc
To show more options for shred:
user:~$ shred --help
Shredding does not work with files on RAID systems or with compressed files.
To overwrite a partition of a hard drive, specify the exact partition number so as not to shred the whole hard drive by mistake.
https://phoenixnap.com/kb/shred-linux
shred - To shred, overwrite and delete a file:
user@user-Z-ED4:~$ shred --help
Usage: shred [OPTION]... FILE...
Overwrite the specified FILE(s) repeatedly, in order to make it harder for even very expensive hardware probing to recover the data.
If FILE is -, shred standard output.
Mandatory arguments to long options are mandatory for short options too.
-f, --force change permissions to allow writing if necessary
-n, --iterations=N overwrite N times instead of the default (3)
Shred utility program is part of coreutils, which is usually installed as part of Linux. If it ever needs to be installed or updated, run
$sudo apt-get install coreutils.
The shred command may not work effectively on the following types of filesystems: JFS, ReiserFS, XFS, Ext3, RAID and NFS. Shred files then if need be, only delete the directory they were in. Do not shred directories, subdirectories or partitions, because Shred leaves old entries in the configuration file /etc/fstab which stop Linux from booting. Copies of files can be retained in file-system backups and on remote mirrors after the files have been shredded and deleted. Use sudo command with shred. Wildcards do not work with shred.
To shred a file:
Change CD into the directory where the file is.
shred -fu filename
The -f option forces a change to the permission of a file to allow it to be overwritten. The -u option cuts and removes the file after it is overwritten.
To be safer with shred, first change directory cd, then list ls the directory to show the file or files to be shredded, then run the command
sudo shred options filename
user@user-Z-ED4:~/Desktop/testshred$ ls
2DO findhow.doc tdout ufwfirewall
user@user-Z-ED4:~/Desktop/testshred$ sudo shred 2DO
user@user-Z-ED4:~/Desktop/testshred$ ls
2DO findhow.doc tdout ufwfirewall
user@user-Z-ED4:~/Desktop/testshred$ sudo gedit 2DO
See that file is shredded and cannot be opened properly.
FFo)/9Z#\D8#\BCmT$\B7#\CB\DB\D2<#\84\C0#c\BA\C0\F0{\85\CB\DDGɳ\C4>F\BA\AEe#8\B3\B6\B5_\A6N\AD\F4)\8E#$\D8l\BBߠv\81#\D8#D\EE\8070\A9\AA#\9A\98"-#\82\C3\C5\F3
\80%\89\AD#Ci-\81e\B3\82S\C3E\DE\F ... etc
To shred overwrite three files:
shred filename.txt file.jpg filecalled.doc
To shred then delete three files, use the -u option:
shred -u filename.txt file.jpg filecalled.doc
To shred and delete a whole partition of a hard drive:
shred -options partitionname
shred -f /dev/sda5
To shred a RAID partition:
shred -vf -n 10 /dev/md1
To shred and erase a whole hard drive:
shred -options drivename
shred -f -n 10 /dev/sda
Wait as Shred takes a long time to overwrite a full drive.
gpg - To encrypt a file so that only you yourself can decrypt it, specify yourself as the recipient.
Change directories cd to the one containing the file to be encrypted. Here the file is called 2DO.
user@user-Z-ED4:~/Desktop$ gpg -c 2DO
The -c option means symmetric keys, not cipher. GPG uses CAST5 cipher algoristhm by default. GPG encrypts by default so the -e for encrypt option does not need to be typed.
At the prompt, type a password and keep note of it.
GPG saves the encrypted .gpg file in the current directory.
To decrypt a .gpg file:
user@user-Z-ED4:~/Desktop$ gpg -d 2DO.gpg
gpg: AES encrypted data
gpg: encrypted with 1 passphrase
Things to do
ask ISP
200 4sb
check file backed up twice
correct command in linuxsudo
user@user-Z-ED4:~/Desktop$
GPG opens the decrypted file as above.
The sender and recipient can be the same person. One use of GPG is to encrypt your own data, storing the ciphertext and destroying the plaintext.
To generate a public/private key pair instead of a one shared key:
gpg --gen-key
To list files in the gpg key directory:
user:~$ ls /home/user/.gnupg/
user@user-Z-ED4:~$ ls /home/user/.gnupg
private-keys-v1.d secring.gpg trustdb.gpg
pubring.gpg S.gpg-agent
user@user-Z-ED4:~$
To show which ciphers algorithms to choose from:
gpg --version
user@user-Z-ED4:~$ gpg --version
gpg (GnuPG) 1.4
Copyright (C) License etc
Home: ~/.gnupg
Supported algorithms:
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2
user@user-Z-ED4:~$
The cipher algorithm chosen could be 3DES whereas AES is used more and the default cipher is CAST5. Note with your password which cipher you use.
To enter and exit GPG text mode: enter with $ gpg ; exit with control-d.
To quit text mode and go back to the Terminal command prompt, control-backstroke, that is ^\, hold the ctrl key down while you press the \ key.
To quit a shell script with several commands in it, press ctrl-\ for each command until you are back at the command prompt.
yne@yne-Z-ED4:~$ gpg
gpg: Go ahead and type your message ...
type message here then ctrl-\
^\
gpg: Quit caught ... exiting
Quit (core dumped)
yne@yne-Z-ED4:~$
That mode is for user and recipent private and public key pairs.
lpstat - To check the status for all of the printers on the system, and the scheduler for all jobs:
# lpstat -t
user@user-M-ED4:~$ sudo lpstat -t
scheduler is running
system default destination: WorkCentre-3119-Series
device for WorkCentre-3119-Series: usb://Xerox/WorkCentre%203119%20Series?serial=EGB383533724....&interface=1
WorkCentre-3119-Series accepting requests since Fri 03 May 2019 01:50:47 PM PGT
printer WorkCentre-3119-Series is idle. enabled since Fri 03 May 2019 01:50:47 PM PGT
user@user-M-ED4:~$
To show a summary of all printers, classes, and associated devices:
$ sudo lpstat -s
user@user-M-ED4:~$ sudo lpstat -s
system default destination: WorkCentre-3119-Series
device for WorkCentre-3119-Series: usb://Xerox/WorkCentre%203119%20Series?serial=EGB383533724....&interface=1
user@user-M-ED4:~$
To show which filing systems are mounted:
$ mount -l
lpr - To use the printer from the command line:
# lpr –P laserjetV –#2 /home/user1/file1
Here -P laserjetV prints to the laserjetV printer, -#2 prints two copies, and /home/user/file1 is the name of the file to be printed.
Many standard lpr options, such as -c and -d, are not available when using cups as the server.
To mount all filing systems specified in the fstab directory:
$ mount -a
To unmount all filing systems:
$ umount -a
To run two or more commands at once, one after another, type a semicolon between them, as in the next example.
blkid ; df - To show the identity, size, format and mount point of drives:
user@user-K-ED4:~$ sudo blkid -o list ; sudo df -haT
device fs_type label mount point UUID
-------------------------------------------------------------------------------
/dev/sda1 ext4 / c4931570-2671-5w66-9826-8u17827876f
/dev/sda5 swap [SWAP] 50feeb57-6d2f-4b31-90a7-bba42251d7a4
/dev/sdb1 ext4 (not mounted) 185ce059-d153-44dc-9eb9-d4737f5c0692
/dev/sdb5 swap (not mounted) edb7b556-327b-4554-9e0c-a7a4f64904ff
/dev/sdc1 ext4 (not mounted) d60b90e4-2d06-476b-95fa-517c25f1d62f
/dev/sdc5 swap (not mounted) 9a4f93f7-832c-42d6-9381-c33fd8a0cc9b
/dev/sdd1 vfat (not mounted) 2D71-12ED
/dev/sdd5 vfat (not mounted) 2245-12FD
Filesystem Type Size Used Avail Use% Mounted on
sysfs sysfs 0 0 0 - /sys
proc proc 0 0 0 - /proc
udev devtmpfs 2.0G 0 2.0G 0% /dev
devpts devpts 0 0 0 - /dev/pts
tmpfs tmpfs 395M 6.5M 389M 2% /run
/dev/sda1 ext4 114G 5.9G 102G 6% /
securityfs securityfs 0 0 0 - /sys/kernel/security
tmpfs tmpfs 2.0G 256K 2.0G 1% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
cgroup cgroup 0 0 0 - /sys/fs/cgroup/systemd
pstore pstore 0 0 0 - /sys/fs/pstore
cgroup cgroup 0 0 0 - /sys/fs/cgroup/cpu,cpuacct
cgroup cgroup 0 0 0 - /sys/fs/cgroup/net_cls,net_prio
cgroup cgroup 0 0 0 - /sys/fs/cgroup/memory
cgroup cgroup 0 0 0 - /sys/fs/cgroup/pids
cgroup cgroup 0 0 0 - /sys/fs/cgroup/freezer
cgroup cgroup 0 0 0 - /sys/fs/cgroup/blkio
cgroup cgroup 0 0 0 - /sys/fs/cgroup/perf_event
cgroup cgroup 0 0 0 - /sys/fs/cgroup/devices
cgroup cgroup 0 0 0 - /sys/fs/cgroup/hugetlb
cgroup cgroup 0 0 0 - /sys/fs/cgroup/cpuset
systemd-1 - - - - - /proc/sys/fs/binfmt_misc
mqueue mqueue 0 0 0 - /dev/mqueue
debugfs debugfs 0 0 0 - /sys/kernel/debug
hugetlbfs hugetlbfs 0 0 0 - /dev/hugepages
fusectl fusectl 0 0 0 - /sys/fs/fuse/connections
tmpfs tmpfs 395M 48K 395M 1% /run/user/1000
gvfsd-fuse fuse.gvfsd-fuse 0.0K 0.0K 0.0K - /run/user/1000/gvfs
binfmt_misc binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc
user@user-K-ED4:~$
To list files and folders in a drive that is mounted, name the drive:
user@user-K-ED4:~$ ls /media/user/"1TB Filesystem"
archive18 Backup lost+found
That drive is called 1TB Filesystem and quotes are needed because there is a space in the name.
To look for a file with a name which has "sudo" in it:
user@user-K-ED4:~$ ls /media/user/"1TB Filesystem"/Backup/
Documents Music Pictures Programs
user@user-K-ED4:~$ find /media/user/"1TB Filesystem"/Backup/Documents/*sudo*
/media/user/1TB Filesystem/Backup/Documents/foremostsudo
/media/user/1TB Filesystem/Backup/Documents/linuxsudobd
/media/user/1TB Filesystem/Backup/Documents/sudocache
/media/user/1TB Filesystem/Backup/Documents/sudocdrom
... etc
/media/user/1TB Filesystem/Backup/Documents/wifisudo
user@user-K-ED4:~$
Find finds the files but Locate does not.
user@user-K-ED4:~$ locate /media/user/"1TB Filesystem"/Backup/Documents/*sudo*
user@user-K-ED4:~$ locate updatedb /media/user/"1TB Filesystem"/Backup/Documents/*sudo*
/etc/updatedb.conf
/etc/alternatives/updatedb
/usr/bin/updatedb
/usr/bin/updatedb.mlocate
/usr/share/man/man5/updatedb.conf.5.gz
/usr/share/man/man8/updatedb.8.gz
user@user-K-ED4:~$ locate /media/user/"1TB Filesystem"/Backup/Documents/*sudo*
user@user-K-ED4:~$
blkid - To show a list of all the drives and partitions with their universal block identity ID:
user@user-K-3:~$ sudo blkid
[sudo] password for user:
/dev/sda1: UUID="202a4711-0ddf-488d-9457-83d6a0e3da99" TYPE="ext4" PTTYPE="dos" PARTUUID="e1884898-01"
/dev/sda2: LABEL="User110gb" UUID="27e906ba-c1f1-4525-a14f-da217e2c890a" TYPE="ext4" PARTUUID="e1884898-02"
/dev/sda5: UUID="4637b17a-abfc-4342-a565-49232a520888" TYPE="swap" PARTUUID="e1884898-05"
... etc
/dev/sdd5: UUID="6b45f31c-f753-46a1-bcbb-d6e4b2110668" TYPE="swap" PARTUUID="5ef6ede9-05"
/dev/sde1: UUID="3151-1014" TYPE="vfat" PARTUUID="2398f9d2-01"
/dev/sde5: UUID="1F48-10DE" TYPE="vfat" PARTUUID="2398f9d2-05"
user@user-K-ED4:~$
If you add a usb, hdd or other drive to the system, the device names may change but the UUID block identity will stay the same to identify the drives.
To use the device finder df to show a second hard disk drive with all file systems shown by default:
user@user-K-ED4:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 977M 0 977M 0% /dev
tmpfs 200M 6.4M 194M 4% /run
/dev/sda1 46G 4.6G 39G 11% /
tmpfs 998M 256K 998M 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 998M 0 998M 0% /sys/fs/cgroup
tmpfs 200M 52K 200M 1% /run/user/1000
/dev/sdb 917G 562G 309G 65% /media/user/a16e639d-c743-4042-858e-85c81eb777bd
user@user-K-ED4:~$
The second hdd drive is 917gb mounted at sdb. An option -a shows all file systems including inaccessible systems. Option -h shows sizes in whole megabytes and gigabytes so they are humanly readable.
To show list of subdirectories in a directory called archive:
user@user-K-ED4:~$ ls /media/user/a16e639d-c743-4042-858e-85c81eb777bd/archive/
antec Desktop Music Recovered
Aopenb Documents Programs Ubuntu One
Aopensave212 examples.desktop Public
user@user-K-ED4:~$
lsblk - To list show partitions that are not mounted, use the list block command.
user@user-K-ED4:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdd 8:48 0 74.5G 0 disk
├─sdd2 8:50 0 1K 0 part
├─sdd5 8:53 0 2G 0 part
└─sdd1 8:49 0 72.5G 0 part
sdb 8:16 0 931.5G 0 disk /media/user/a16e639d-c743-4042-8
sr0 11:0 1 1024M 0 rom
fd0 2:0 1 4K 0 disk
... etc
sda 8:0 0 149.1G 0 disk
├─sda2 8:2 0 53G 0 part
├─sda5 8:5 0 49.6G 0 part [SWAP]
├─sda3 8:3 0 1K 0 part
└─sda1 8:1 0 46.6G 0 part /
user@user-K-ED4:~$
One hard drive above is mounted.
locate - To locate find any mention of a word in the files in the current working directory:
Here we change cd to the Desktop.
tom@host-id:~$ cd ~/Desktop
tom@host-id:~/Desktop$
The word to find goes between asterisks *word*.
tom@host-id:~/Desktop$ locate *burger*
/home/tom7/Desktop/spudburger
tom@host-id:~/Desktop$
The file names spudburger mentions the word burger.
To install Locate:
tom@host-id:~/Desktop$ sudo apt install plocate
[sudo] password for tom7:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed etc y yes
To mount the second 1tb hddrive then show what directories are on it:
user@user-K-ED4:~$ sudo mount /dev/sdc1 /media/
[sudo] password for user:
user@user-K-ED4:~$ ls
Desktop Downloads Music Public Videos
Documents examples.desktop Pictures Templates
user@user-K-ED4:~$ ls /media
archive18 Backup lost+found
user@user-K-ED4:~$
parted - To list drive partitions that are not mounted:
user@user-K-ED4:~$ sudo parted -l
[sudo] password for user:
Model: ATA WDC WD1600AAJS-0 (scsi)
Disk /dev/sda: 160GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 50.0GB 50.0GB primary ext4 boot
2 50.0GB 107GB 56.8GB primary ext4
3 107GB 160GB 53.2GB extended
5 107GB 160GB 53.2GB logical linux-swap(v1)
Model: ATA ST1000DM010-2EP1 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 1000GB 1000GB ext4
Model: ATA SAMSUNG HD103UJ (scsi)
Disk /dev/sdc: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 32.3kB 1000GB 1000GB primary ext4
Model: ATA ST380011A (scsi)
Disk /dev/sdd: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 77.9GB 77.9GB primary ext4 boot
2 77.9GB 80.0GB 2140MB extended
5 77.9GB 80.0GB 2140MB logical linux-swap(v1)
Model: ATA SAMSUNG SP0411N (scsi)
Disk /dev/sde: 40.1GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 32.3kB 32.0GB 32.0GB primary fat32 boot, lba
2 32.0GB 40.1GB 8011MB extended lba
5 32.0GB 40.1GB 8011MB logical fat32
user@user-K-ED4:~$
To list all mounted and unmounted drive partitions:
user@user-K-ED4:~$ sudo blkid -o list
device fs_type label mount point UUID
-----------------------------------------------------------------
/dev/sda1 ext4 / 202a4711-0ddf-488d-9457-83d6a0e3da99
/dev/sda2 ext4 User110gb (not mounted) 27e906ba-c1f1-4525-a14f-da217e2c890a
/dev/sda5 swap [SWAP] 4637b17a-abfc-4342-a565-49232a520888
/dev/sdb ext4 (in use) a16e639d-c743-4042-858e-85c81eb777bd
/dev/sdc1 ext4 1TB Filesystem /media 18686e60-ecca-4bd0-aad5-c8a086fff25a
/dev/sdd1 ext4 (not mounted) 8bd88b0a-0a20-4a09-beea-200fa241d69e
/dev/sdd5 swap (not mounted) 6b45f31c-f753-46a1-bcbb-d6e4b2110668
/dev/sde1 vfat (not mounted) 3151-1014
/dev/sde5 vfat (not mounted) 1F48-10DE
user@user-K-ED4:~$
Option -o list says to format the output as a list.
To show a list of all the drives and partitions with their universal identity ID:
user@user-K-3:~$ sudo blkid
[sudo] password for user:
/dev/sda1: UUID="202a4711-0ddf-488d-9457-83d6a0e3da99" TYPE="ext4" PTTYPE="dos" PARTUUID="e1884898-01"
/dev/sda2: LABEL="User110gb" UUID="27e906ba-c1f1-4525-a14f-da217e2c890a" TYPE="ext4" PARTUUID="e1884898-02"
/dev/sda5: UUID="4637b17a-abfc-4342-a565-49232a520888" TYPE="swap" PARTUUID="e1884898-05"
... etc
/dev/sdc1: LABEL="1TB Filesystem" UUID="18686e60-ecca-4bd0-aad5-c8a086fff25a" TYPE="ext4" PARTUUID="000a121f-01"
/dev/sdd1: UUID="8bd88b0a-0a20-4a09-beea-200fa241d69e" TYPE="ext4" PARTUUID="5ef6ede9-01"
/dev/sdd5: UUID="6b45f31c-f753-46a1-bcbb-d6e4b2110668" TYPE="swap"
user@user-K-ED4:~$
To exit Gedit while in Terminal, save and close the file you are looking at, then in Terminal press ctrl-shift-q for quit.
To mount a separate hard drive in the same computer box: -
The name of the separate drive device here is /dev/sdc1 and the path to the mount point is /media/user/"1TB Filesystem"/
user@user-K-ED4:/$ sudo mount /dev/sdc1 /media/user/"1TB Filesystem"/
mount: /dev/sdc1 is already mounted or /media/user/1TB Filesystem busy
/dev/sdc1 is already mounted on /media/user/1TB Filesystem
user@user-K-ED4:/$
The drive was already mounted, as was shown by the earlier command sudo blkid -o list ; sudo df -haT.
Linux commands
How to use commands with Ubuntu terminal program. Most of these commands also work on the Linux command line for Slackware and Debian.
To find a command, search this file for a key word. Many keywords are used redundantly below to help with searching.
To run commands in Terminal:
Usually type commands after the dollar $ sign on the command line, not the hash # sign. Stay with default settings so as not to break anything in the operating system.
To copy a file to a system directory, run the command on a sudo command line after the # sign. Only an administrator has permission to do that.
To start Terminal - ubuntu, applications, accessories, terminal;
or ctrl-alt-t .
To scroll the Terminal screen, click the scroll bar at right. Do not press an up or down arrow key.
To clear or erase a command or typing mistake before it is executed, press the backspace key.
To run a command as the administrator, superuser, as the "root" user, type or cut and paste the "sudo " at the command line. Do not type the quote marks or the <> more or less marks as part of a command. A command prompt ends with a $ or # sign. Type or past a command after the $ or #.
For example, user@user-5GM-S2T:~$ sudo
Press the enter key to run or execute the typed command.
A wrongly typed sudo command can damage or ruin the Linux system.
Only run commands copied from reliable websites, not from forums or blogs.
Sudo requires the administrator's password, not the root account password. If the only user of the computer is the administrator, that is the superuser, then his user password may be the same as his administrator password.
Never use a sudo command to start graphical programs. Use gksudo or kdesudo instead.
To run a command which needs root privileges in a terminal window, type sudo in front of that command.
An administrator can open a window called a root shell which lets him type sudo commands without typing the word "sudo".
To open an interactive root shell, that is a window where you type only sudo commands, type sudo -i
user@localhost-IDnumber:~$ sudo -i
[sudo] password for tom7:
root@localhost-ID:~#
A command prompt in a root shell, for an administrator, ends with hash mark #. A command prompt in a normal terminal window for both administrators and other users ends with a $ sign.
Only system administrators need to run sudo commands or shells. Other users run ordinary commands.
To exit a shell function.
root@user7-356HZM-S2:~# return
or exit
root@host:~# exit
logout
user@host:~$
Linux commands are case sensitive.
To quit the command shell and exit Terminal.
root@user:~# return
-bash: return: can only `return' from a function or sourced script
root@user7-356HZM-S2:~# exit
logout
user7user:/$,
To use an Ubuntu Live cd to find and rescue save user files from a failing hard drive or corrupted operating system: -
Open a root shell with this command:
ubuntu@ubuntu:/$ sudo -i
then run these commands
root@ubuntu:~# cd /media
root@ubuntu:/media# ls
311part 313syspart apt New Volume
Here are two hard drive part partitions and one USB stick called New Volume.
root@ubuntu:/media/313syspart# cd /media/313syspart/home
Here jack is the username.
root@ubuntu:/media/313syspart/home# ls
jack user
Those are two user directories.
root@ubuntu:/media/313syspart/home# cd /media/313syspart/home/jack
root@ubuntu:/media/313syspart/home/jack# ls
Desktop Downloads Music Programs Templates
Documents examples.desktop Pictures Public Videos
root@ubuntu:/media/313syspart/home/jack# cd /media/313syspart/home/jack/Documents
root@ubuntu:/media/313syspart/home/jack/Documents# ls
bridges hazel Gerhow
Only three files to rescue.
root@ubuntu:/media/313syspart/home/jack/Documents# cp bridges hazel MetaGerhow /media/New Volume
cp: target `Volume' is not a directory
Terminal cannot see the USB stick because it has a space in its name New Volume. Use an asterisk wildcard.
root@ubuntu:/media/313syspart/home/jack/Documents# cp bridges hazel MetaGerhow /media/New*
root@ubuntu:/media/313syspart/home/jack/Documents#
Three files have been copied to the usb stick. Safely remove and eject the stick.
To help Terminal read the long name of a directory, use an asterisk * wildcard.
root@ubuntu:/media/313syspart/home/jack/Documents# cp bridges hazel MetaGerhow /media/New Volume
cp: target `Volume' is not a directory
Terminal cannot see the USB stick because it has a space in its name New Volume. Type an asterist wildcard.
root@ubuntu:/media/313syspart/home/jack/Documents# cp bridges hazel MetaGerhow /media/New*
root@ubuntu:/media/313syspart/home/jack/Documents#
Three files have been copied to the usb stick.
To show the files content of a folder or directory:
user7@user7-356HZM-S2:/$ ls ~/documents
ls: cannot access /home/user7/documents: No such file or directory
Try a capital D.
user7@user7-356HZM-S2:/$ ls ~/Documents
ab25815.odt
ab29515.pdf
etc ..
vistause.txt
viuse
user4.gif
firewall2.kmfnet
webnews.txt
..etc ..
wiring
xchat
zombie
To backup a configuration file, like sources.list, before editing it.
user7@user7-356HZM-S2:~$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
[sudo] password for user7:
user7@user7-356HZM-S2:~$ ls /etc/apt/
apt.conf.d sources.list sources.list.save trusted.gpg~
preferences.d sources.list.backup trustdb.gpg trusted.gpg.d
secring.gpg sources.list.d trusted.gpg
user7@user7-356HZM-S2:~$
To open and edit a file called sources.list, using Gedit text editor: -
First backup the file as above.
user7@user7-356HZM-S2:/$ gedit /etc/apt/sources.list
deb cdrom:[Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)]/ maverick main restricted
# Mount package source cdrom or DVD in root directory called /cdrom .
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
Manually typed the following line into the sources file.
deb file:///home/user7/repository/ maverick main universe multiverse restricted
If a line does not work, comment it out with a hash # sign or delete it.
# deb file:///home/user7/repository /
No line is needed for the cdrom because it must be manually remounted to /cdrom for apt to find it automatically.
To return to the Terminal command prompt:
File menu save close quit.
To update the sources list:
user7@user7-356HZM-S2:/$ apt-get update
E: Malformed line 54 in source list /etc/apt/sources.list (dist)
user77@user77-356HZM-S2:~/repository$ sudo apt-get update
Ign file: Release.gpg
Ign file:/home/user77/repository/ Translation-en
... etc ...
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007) maverick/main i386 Packages/DiffIndex
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007) maverick/restricted i386 Packages/DiffIndex
Reading package lists... Done
user77@user77-356HZM-S2:~/repository$
That shows that apt also finds the Ubuntu cdrom disk as a source.
The apt update errors fail and error err mean that package items failed to download. Ign means some package items did not need to be downloaded because they were already downloaded. This line works right without errors in the sources-list
deb file:///home/user7/repository /
To use a second Terminal window to remount a cdrom while apt is updating sources for a repository: -
Apt-get update halts with this message.
Ign file: ./ Packages
Media change: please insert the disc labeled
'Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)'
in the drive '/cdrom/' and press enter
Open a second terminal to remount the cdrom for apt.
user7@user7-356HZM-S2:~$ sudo umount /media/Ubuntu*
[sudo] password for user7:
user7@user7-356HZM-S2:~$ sudo mount /dev/sr0 /cdrom
user7@user7-356HZM-S2:~$
Exit the 2nd terminal. With cursor in the 1st terminal, press enter.
Media change: please insert the disc labeled
'Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)'
in the drive '/cdrom/' and press enter
Enter key.
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en_US
82% [Working]
etc ...
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007) maverick/restricted i386 Packages/DiffIndex
Reading package lists... Done
user7@user7-356HZM-S2:~/repository$
To add a source line to the sources list: -
Include the single quote marks.
user7@user7-356HZM-S2:/$ sudo add-apt-repository 'deb file:///home/user7/repository /'
user7@user7-356HZM-S2:/$ sudo gedit /etc/apt/sources.list
See the new line a the bottom of the list.
## developers who want to ship their latest software.
## deb http://extras.ubuntu.com/ubuntu maverick main
## deb-src http://extras.ubuntu.com/ubuntu maverick main
deb file:///home/user7/repository /
deb-src file:///home/user7/repository /
Save, close and quit gedit.
Run apt-get update to refresh the list.
To add an ftp mirror to the souces.list, use a line like this:
deb ftp://ftp.debian.org/debian lenny contrib
To show the download links of software packages needed for a program to be installed:
user7@user7-356HZM-S2:/$ sudo apt-get --print-uris install dpkg-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
dpkg-dev is already the netomt version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
dpkg-dev : Depends: patch but it is not going to be installed
Recommends: build-essential but it is not going to be installed
Recommends: fakeroot but it is not going to be installed
Recommends: libalgorithm-merge-perl but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
user7@user7-356HZM-S2:/$
That shows which packages to manually download to the hard drive and install offline using dpkg,
Apt-get finds the package information in its repository map in /var/lib/apt/lists and its sources.list at /etc/apt/sources.list .
To install a program from packages on the hard drive: -
Copy the packages to a separate folder. Change to that folder directory.
user7@user7-356GZM-S2:/$ cd ~/install
user7@user7-356GZM-S2:~/install$ ls
apt-offline_1.1.1build1_all.deb python2.7-dev_2.7-6_i386.deb
Here one program needs another so packages for both are in the directory.
Use a wildcard to install all packages.deb
user7@user7-356GZM-S2:~/install$ sudo dpkg -i *.deb
[sudo] password for user7:
(Reading database ... 128388 files and directories currently installed.)
Preparing to replace apt-offline 1.1.1build1 (using apt-offline_1.1.1build1_all.deb) ...
Unpacking replacement apt-offline ...
Selecting previously deselected package python2.7-dev.
Unpacking python2.7-dev (from python2.7-dev_2.7-6_i386.deb) ...
dpkg: dependency problems prevent configuration of apt-offline:
apt-offline depends on python2.7; however:
Package python2.7 is not installed.
apt-offline depends on python (>= 2.7.1-0ubuntu2); however:
Version of python on system is 2.6.6-2ubuntu2.
dpkg: error processing apt-offline (--install):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python2.7-dev:
python2.7-dev depends on python2.7 (= 2.7-6); however:
Package python2.7 is not installed.
python2.7-dev depends on libpython2.7 (= 2.7-6); however:
Package libpython2.7 is not installed.
python2.7-dev depends on libexpat1-dev; however:
Package libexpat1-dev is not installed.
python2.7-dev depends on libssl-dev; however:
Package libssl-dev is not installed.
dpkg: error processing python2.7-dev (--install):
dependency problems - leaving unconfigured
Processing triggers for doc-base ...
Processing 1 changed doc-base file(s)...
Registering documents with scrollkeeper...
Processing triggers for man-db ...
Errors were encountered while processing:
apt-offline
python2.7-dev
user7@user7-356GZM-S2:~/install$
That installation failed as library packages needed to be copied into the directory.
To find whether a missing library dependency file is in the local repository: -
user7@user7-356HZM-S2:~/repository$ filezilla
filezilla: error while loading shared libraries: libtinyxml.so.2.5.3: cannot open shared object file: No such file or directory
user7@user7-356HZM-S2:~/repository$ ls libtinyxml.so.2.5.3
ls: cannot access libtinyxml.so.2.5.3: No such file or directory
user7@user7-356HZM-S2:~/repository$ ls libtinyxml.so
ls: cannot access libtinyxml.so: No such file or directory
user7@user7-356HZM-S2:~/repository$ ls libtinyxml
ls: cannot access libtinyxml: No such file or directory
user7@user7-356HZM-S2:~/repository$
That shows there is no file like it in the repository.
To install a program package with its dependency packages: -
Copy the program package to a separate directory.
user7@user7-356HZM-S2:/var/cache/apt$ cd /var/cache/apt/archives
user7@user7-356HZM-S2:/var/cache/apt/archives$ ls
dpkg-dev_1.15.8.4ubuntu3_all.deb dpkg-dev.deb partial
dpkg-dev_1.16.18_all.deb lock
Try to install it with dpkg to find out its dependencies.
user7@user7-356HZM-S2:/var/cache/apt/archives$ sudo dpkg -i dpkg-dev_1.15.8.4ubuntu3_all.deb
(Reading database ... 128348 files and directories currently installed.)
Preparing to replace dpkg-dev 1.15.8.4ubuntu3 (using dpkg-dev_1.15.8.4ubuntu3_all.deb) ...
Unpacking replacement dpkg-dev ...
dpkg: dependency problems prevent configuration of dpkg-dev:
dpkg-dev depends on patch; however:
Package patch is not installed.
dpkg: error processing dpkg-dev (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db ...
Errors were encountered while processing:
dpkg-dev
Find the missing dependency patch and copy it into that same separate directory.
user7@user7-356HZM-S2:/var/cache/apt/archives$ ls ~/repository/patch*
/home/user7/repository/patch_2.6-2ubuntu1_i386.deb
user7@user7-356HZM-S2:/var/cache/apt/archives$ sudo cp /home/user7/repository/patch_2.6-2ubuntu1_i386.deb /var/cache/apt/archives
user7@user7-356HZM-S2:/var/cache/apt/archives$ ls
dpkg-dev_1.15.8.4ubuntu3_all.deb dpkg-dev.deb partial
dpkg-dev_1.16.18_all.deb lock patch_2.6-2ubuntu1_i386.deb
To install the program and dependencies together: -
user7@user7-356HZM-S2:/var/cache/apt/archives$ sudo dpkg -i dpkg-dev_1.15.8.4ubuntu3_all.deb patch_2.6-2ubuntu1_i386.deb
(Reading database ... 128348 files and directories currently installed.)
Preparing to replace dpkg-dev 1.15.8.4ubuntu3 (using dpkg-dev_1.15.8.4ubuntu3_all.deb) ...
Unpacking replacement dpkg-dev ...
Selecting previously deselected package patch.
Unpacking patch (from patch_2.6-2ubuntu1_i386.deb) ...
Setting up patch (2.6-2ubuntu1) ...
Processing triggers for man-db ...
Setting up dpkg-dev (1.15.8.4ubuntu3) ...
user7@user7-356HZM-S2:/var/cache/apt/archives$
Run apt-get to reload or update the sources list.
more - To open a file to read its contents, to read more: -
user7@user7-356HZM-S2:/$ more ~/Documents/viuse
How to use Vi text editor in Linux Slackware
Vi text editor is on all UNIX and similar systems. It has two modes: command mod
e and insert mode. Keys behave differently in each mode.
... etc
more press spacebar
"!" then attempt to run it as a command to the shell.
vimtutor user manual
user7@user7-356HZM-S2:/$
To find commands for using Nano text editor as an alternative to Gedit or Vi.
user7@user7-356HZM-S2:~$ cd /
user7@user7-356HZM-S2:/$ nano --help
Usage: nano [OPTIONS] [[+LINE,COLUMN] FILE]...
Option GNU long option Meaning
-h, -? --help Show this message
+LINE,COLUMN Start at line LINE, column ...etc
See www.nano-editor.org for usage.
To show the name and ID identity of a compact disk CD in a drive: -
Insert disk into drive.
user7@user7-356HZM-S2:/$ apt-cdrom ident
Using CD-ROM mount point /cdrom/
Mounting CD-ROM
E: Failed to mount the cdrom.
user7@user7-356HZM-S2:/$
The cd may be mounted to /media instead of /cdrom directory.
Use a wildcard * asterisk to see what is in /media/Ubuntu dir.
user7@user7-356HZM-S2:/media/cdrom$ cd /media/Ubuntu*
user7@user7-356HZM-S2:/media/Ubuntu 10.10 i386$ ls
autorun.inf dists md5sum.txt preseed usb-creator.exe
boot install pics README.diskdefines wubi.exe
casper isolinux pool ubuntu
user7@user7-356HZM-S2:/media/Ubuntu 10.10 i386$
To Unmount the disk and remount it where apt can find it, use the command apt-cdrom add.
To add a drive to the sources list use apt-cdrom command to add it automatically as a drive cannot be added by hand.
user7@user7-356HZM-S2:/$ sudo apt-cdrom add
[sudo] password for user7:
Using CD-ROM mount point /media/apt/
Identifying.. [2a56aeb2c43c1c4b0cc69a3963228c80-2]
Scanning disc for index files..
Found 0 package indexes, 0 source indexes, 0 translation indexes and 0 signatures
Using CD-ROM mount point /media/apt/
Identifying.. [2a56aeb2c43c1c4b0cc69a3963228c80-2]
Scanning disc for index files..
W: Failed to mount '/dev/sr0' to '/media/apt/'
E: Unable to locate any package files, perhaps this is not a Debian Disc or the wrong architecture?
W: Failed to mount '/dev/sr1' to '/media/apt/'
user7@user7-356HZM-S2:/$
Try another disk.
Ubuntu Terminal lists packages orange, files white and directories light blue. See that the cursor is solid white and flashing, click it, before starting to type a command.
Tp see show where Ubuntu has automatically mounted a USB stick:
user7@user7-356HZM-S2:/$ ls /media
apt cdrom floppy floppy0 iso New Volume Ubuntu12set usb
The memory stick called New Volume is mounted in the directory /media .
To show the iso imgage files listed on a dvd: -
Put the DVD into the cdrom drive. Ubuntu will automatically mount it to /media directory.
user7@user7-356HZM-S2:~$ ls /media
apt cdrom floppy floppy0 iso Ubuntu12iso usb
user7@user7-356HZM-S2:~$ cd /media/Ubuntu12iso
user7@user7-356HZM-S2:/media/Ubuntu12iso$ ls
ubuntu-12.04.2-desktop-i386
user7@user7-356HZM-S2:/media/Ubuntu12iso$ cd /media/Ubuntu12iso/ubuntu-12.04.2-desktop-i386
user7@user7-356HZM-S2:/media/Ubuntu12iso/ubuntu-12.04.2-desktop-i386$ ls
autorun.inf casper install md5sum.txt pool README.diskdefines
boot dists isolinux pics preseed wubi.exe
user7@user7-356HZM-S2:/media/Ubuntu12iso/ubuntu-12.04.2-desktop-i386$
To eject a dvd which is busy with Terminal: -
Exit terminal.
Open a new terminal window.
Type the command eject and press the return or enter key.
To eject a cdrom from a different mount point:
user7@user7-356HZM-S2:/$ sudo eject /cdrom
To remount a dvd iso imgage to the /media/iso directory.
user7@user7-356HZM-S2:/$ ls /media
apt cdrom floppy floppy0 usb
user7@user7-356HZM-S2:/$ sudo mkdir /media/iso
[sudo] password for user7:
user7@user7-356HZM-S2:/$ ls /media
apt cdrom floppy floppy0 iso usb
Insert the dvd containing iso.
user7@user7-356HZM-S2:/$ ls /media
apt cdrom floppy floppy0 iso Ubuntu12set usb
The iso is called Ubuntu12set.
First unmount it or a block device error will show.
user7@user7-356HZM-S2:/$ sudo mount /media/Ubuntu12* /media/iso
mount: /media/Ubuntu12set is not a block device
user7@user7-356HZM-S2:/$ ls /media
apt cdrom floppy floppy0 iso New Volume Ubuntu12set usb
user7@user7-356HZM-S2:/$ sudo umount /media/Ubuntu12*
[sudo] password for user7:
user7@user7-356HZM-S2:/$
user7@user7-356HZM-S2:/$ sudo mount /dev/sr0 /media/iso
user7@user7-356HZM-S2:/$ ls /media/iso
ubuntu-12.04.2-desktop-i386
user7@user7-356HZM-S2:/$
To show information about the status -s of a package, whether it is installed.
user7@user7-356GZM-S2:~$ sudo dpkg -s python
[sudo] password for user7:
Package: python
Status: install ok installed
Priority: important
Section: python
Installed-Size: 752
Maintainer: Ubuntu Developers
Architecture: all
Source: python-defaults
Version: 2.6.6-2ubuntu2
Replaces: python-dev (<< 2.6.5-2)
Provides: python-ctypes, python-email, python-wsgiref
Depends: python2.6 (>= 2.6.6-1~), python-minimal (= 2.6.6-2ubuntu2)
Suggests: python-doc (= 2.6.6-2ubuntu2), python-tk (= 2.6.6-2ubuntu2), python-profiler (= 2.6.6-2ubuntu2)
Breaks: python-bz2 (<< 1.1-8), python-csv (<< 1.0-4), python-email (<< 2.5.5-3)
Conflicts: python-central (<< 0.5.5)
Description: interactive high-level object-oriented language (default version)
Python, the high-level, interactive object oriented language,
includes an extensive class library with lots of goodies for
network programming, system administration, sounds and graphics. .
This package is a dependency package, which depends on Debian's default
Python version (currently v2.6).
Original-Maintainer: Matthias Klose
Homepage: http://www.python.org/
user7@user7-356GZM-S2:~$
To remove uninstall purge a package: -
In this example the package name is lilypond-doc.
user7@user7-356HZM-S2:/$ sudo dpkg --purge lilypond-doc
(Reading database ... 141081 files and directories currently installed.)
Removing lilypond-doc ...
Processing triggers for doc-base ...
Processing 1 removed doc-base file(s)...
Registering documents with scrollkeeper...
Processing triggers for install-info ...
user7@user7-356HZM-S2:/$
Update sources list.
user7@user7-356HZM-S2:/$ sudo apt-get update
To remove a package and its configuration files too:
sudo apt-get --purge remove packagename.
To check to verify that there are no broken dependencies:
user7@user7-356HZM-S2:/$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
user7@user7-356HZM-S2:/$
To clean away remove purge uninstall a broken package. This package is called fakeroot.
ne7@user7-356HZM-S2:~$ sudo apt-get clean fakeroot
user7@user7-356HZM-S2:~$ sudo apt-get update
Ign file: ./ Release.gpg
Ign file:/home/user7/repository/ ./ Translation-etc .. been ignored, or old ones used instead.
user7@user7-356HZM-S2:~$
To remove a broken package: -
Broken package is called dpkg-dev.
user7@user7-356HZM-S2:~$ sudo dpkg --remove dpkg-dev
(Reading database ... 128605 files and directories currently installed.)
Removing dpkg-dev ...
Processing triggers for man-db ...
user7@user7-356HZM-S2:~$
Run apt-get update.
To check for, clean and remove broken packages: -
user7@user7-356GZM-S2:/$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
aptitude : Depends: aptitude-common (= 0.6.8.2-1) but it is not installable
Depends: libapt-pkg4.12 (>= 0.9.7.6) but it is not installable
Depends: libboost-iostreams1.49.0 (>= 1.49.0-1) but it is not installable
Depends: libcwidget3 but it is not installable
Depends: libept1.4.12 (>= 1.0.9) but it is not installable
Depends: libstdc++6 (>= 4.6) but 4.5.1-7ubuntu2 is installed
Depends: libtinfo5 but it is not installable
Depends: libxapian22 but it is not installable
Recommends: libparse-debianchangelog-perl but it is not installable
aptitude-gtk : Depends: aptitude (= 0.6.3-2ubuntu4) but 0.6.8.2-1 is installed
Depends: libboost-iostreams1.42.0 (>= 1.42.0-1) but
E: Unmet dependencies. Try using -f.
user7@user7-356GZM-S2:/$ sudo apt-get clean aptitude
user7@user7-356GZM-S2:/$ sudo dpkg --remove aptitude
(Reading database ... 128762 files and directories currently installed.)
Removing aptitude ...
Processing triggers for man-db ...
user7@user7-356GZM-S2:/$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
aptitude-gtk : Depends: aptitude (= 0.6.3-2ubuntu4) but it is not installable
Depends: libboost-iostreams1.42.0 (>= 1.42.0-1) but it is not installable
Depends: libcwidget3 but it is not installable
Depends: libglademm-2.4-1c2a (>= 2.6.0) but it is not installable
lilypond-data : Depends: texinfo but it is not installable or
texlive-texinfo but it is not installable
Depends: texlive-base-bin but it is not installable
Recommends: lilypond (>= 2.12.3-7) but it is not installable
E: Unmet dependencies. Try using -f.
user7@user7-356GZM-S2:/$ sudo dpkg --remove aptitude-gtk
(Reading database ... 128741 files and directories currently installed.)
Removing aptitude-gtk ...
Processing triggers for desktop-file-utils ...
Processing triggers for python-gmenu ...
Rebuilding /usr/share/applications/desktop.en_US.utf8.cache...
Processing triggers for python-support ...
user7@user7-356GZM-S2:/$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
user7@user7-356GZM-S2:/$
To try to force fix -f correct a system with broken dependencies in place: Here dpkg-dev is the name of a broken package. Generally do not force packages to install as it damages the system.
user7@user7-356HZM-S2:~$ sudo apt-get -f install dpkg-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
dpkg-dev is already the netomt version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
dpkg-dev : Depends: libdpkg-perl (= 1.15.8.4ubuntu3) but it is not going to be installed
Depends: patch but it is not going to be installed
Recommends: build-essential but it is not going to be installed
Recommends: fakeroot but it is not going to be installed
Recommends: libalgorithm-merge-perl but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
user7@user7-356HZM-S2:~$
To see show information about an uninstalled package in the local repository:
user7@user7-356GZM-S2:~/repository$ sudo dpkg --info ~/repository/apt-dpkg-ref_5.3+nmu1_all.deb
new debian package, version 2.0.
size 96696 bytes: control archive= 811 bytes.
505 bytes, 12 lines control
695 bytes, 9 lines md5sums
Package: apt-dpkg-ref
Priority: optional
Section: doc
Installed-Size: 152
Maintainer: Ubuntu Developers
Architecture: all
Version: 5.3+nmu1
Description: APT, Dpkg Quick Reference sheet
A quick lookup chart with various APT and dpkg options for handy reference,
for those who haven't quite memorized the most commonly used commands. .
(Repackaged on Sat, 26 Sep 2015 17:55:56 +1000 by dpkg-repack.)
Original-Maintainer: Vanessa Gutiérrez
user7@user7-356GZM-S2:~/repository$
That apt program is optional.
To install it, press the up arrow and edit the command.
user7@user7-356GZM-S2:~/repository$ sudo dpkg -i ~/repository/apt-dpkg-ref_5.3+nmu1_all.deb
Selecting previously deselected package apt-dpkg-ref.
(Reading database ... 128359 files and directories currently installed.)
Unpacking apt-dpkg-ref (from .../apt-dpkg-ref_5.3+nmu1_all.deb) ...
Setting up apt-dpkg-ref (5.3+nmu1) ...
Processing triggers for doc-base ...
Processing 1 added doc-base file(s)...
Registering documents with scrollkeeper...
user7@user7-356GZM-S2:~/repository$
To tell apt the mount point directory where the disk is mounted:
user7@user7-356HZM-S2:/$ sudo apt-cdrom -d=/media/Ubuntu* add
Using CD-ROM mount point /media/apt/
Identifying.. [4f943d3f6ad91143653749c84d630b8b-2]
Scanning disc for index files..
Found 0 package indexes, 0 source indexes, 0 translation indexes and 0 signatures
Using CD-ROM mount point /media/apt/
Identifying.. [4f943d3f6ad91143653749c84d630b8b-2]
Scanning disc for index files..
apt-mirror --helpW: Failed to mount '/dev/sr0' to '/media/apt/'
E: Unable to locate any package files, perhaps this is not a Debian Disc or the wrong architecture?
W: Failed to mount '/dev/sr1' to '/media/apt/'
user7@user7-356HZM-S2:/$
To find the mount point where apt-cdrom expects to find a disk: - Eject the CD disk and run this command with the drive empty.
user7@user7-356HZM-S2:/$ sudo apt-cdrom add
[sudo] password for user7:
Using CD-ROM mount point /media/apt/
Identifying.. [8d11fec3871fac0679e5efd47024369a-2]
Scanning disc for index files..
Found 0 package indexes, 0 source indexes, 0 translation indexes and 0 signatures
Using CD-ROM mount point /media/apt/
Identifying.. [8d11fec3871fac0679e5efd47024369a-2]
Scanning disc for index files..
W: Failed to mount '/dev/sr0' to '/media/apt/'
E: Unable to locate any package files, perhaps this is not a Debian Disc or the wrong architecture?
W: Failed to mount '/dev/sr1' to '/media/apt/'
user7@user7-356HZM-S2:/$ sudo apt-cdrom add
Using CD-ROM mount point /media/apt/
Identifying.. [8d11fec3871fac0679e5efd47024369a-2]
Scanning disc for index files..
Found 0 package indexes, 0 source indexes, 0 translation indexes and 0 signatures
Using CD-ROM mount point /media/apt/
Identifying.. [f4c6b3f01ef98a7e08e3fec3b6c49411-2]
Scanning disc for index files..
W: Failed to mount '/dev/sr0' to '/media/apt/'
E: Unable to locate any package files, perhaps this is not a Debian Disc or the wrong architecture?
W: Failed to mount '/dev/sr1' to '/media/apt/'
user7@user7-356HZM-S2:/$
So apt-cdrom would mount a disk to /media/apt/ directory.
Unmount the disk and remount it to that directory instead.
user7@user7-356HZM-S2:/$ sudo mount /dev/sr0 /media/apt
user7@user7-356HZM-S2:/$ sudo apt-cdrom add
Using CD-ROM mount point /media/apt/
Identifying.. [e6fbe1571743a7752d144a427af01351-2]
Scanning disc for index files..
Found 2 package indexes, 0 source indexes, 0 translation indexes and 1 signatures
This disc is called:
'Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)'
Copying package lists...gpgv: Signature made Fri 08 Oct 2010 03:24:55 AM EST using DSA key ID FBB75451
gpgv: Good signature from "Ubuntu CD Image Automatic Signing Key "
Reading Package Indexes... Done
Writing new list
Source list entries for this disc are:
deb cdrom:[Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)]/ maverick main restricted
Using CD-ROM mount point /media/apt/
Identifying.. [e6fbe1571743a7752d144a427af01351-2]
Scanning disc for index files..
Found 2 package indexes, 0 source indexes, 0 translation indexes and 1 signatures
This disc is called:
'Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)'
Copying package lists...gpgv: Signature made Fri 08 Oct 2010 03:24:55 AM EST using DSA key ID FBB75451
gpgv: Good signature from "Ubuntu CD Image Automatic Signing Key "
Writing new source list
Source list entries for this disc are:
deb cdrom:[Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)]/ maverick main restricted
Repeat this process for the rest of the CDs in your set.
W: Skipping nonexistent file /media/apt/dists/maverick/main/binary-i386/Packages
W: Skipping nonexistent file /media/apt/dists/maverick/restricted/binary-i386/Packages
W: Skipping nonexistent file /media/apt/dists/maverick/main/binary-i386/Packages
W: Skipping nonexistent file /media/apt/dists/maverick/restricted/binary-i386/Packages
To update reload the sources list package index.
user7@user7-356HZM-S2:/$ sudo apt-get update
Err http://archive.canonical.com maverick Release.gpg
Something wicked happened resolving 'archive.canonical.com:http' (-5 - No address associated with hostname)
Err http://archive.canonical.com/ubuntu/ maverick/partner Translation-en
Something wicked happened resolving 'archive.canonical.com:http' (-5 - No address associated with hostname)
Err http://archive.canonical.com/ubuntu/ maverick/partner Translation-en_US
Something wicked happened resolving 'archive.canonical.com:http' (-5 - No address associated with hostname)
Ign http://archive.canonical.com maverick Release
Ign http://archive.canonical.com maverick/partner Sources
Ign http://archive.canonical.com maverick/partner i386 Packages
Ign http://archive.canonical.com maverick/partner Sources
Ign http://archive.canonical.com maverick/partner i386 Packages
Err http://archive.canonical.com maverick/partner Sources
Something wicked happened resolving 'archive.canonical.com:http' (-5 - No address associated with hostname)
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en
Err http://archive.canonical.com maverick/partner i386 Packages
Something wicked happened resolving 'archive.canonical.com:http' (-5 - No address associated with hostname)
Ign file: maverick Release.gpg
Ign file:/home/user7/repository/ maverick/main Translation-en
Ign file:/home/user7/repository/ maverick/main Translation-en_US
Ign file:/home/user7/repository/ maverick/multiverse Translation-en
Ign file:/home/user7/repository/ maverick/multiverse Translation-en_US
Ign file:/home/user7/repository/ maverick/restricted Translation-en
Ign file:/home/user7/repository/ maverick/restricted Translation-en_US
Ign file:/home/user7/repository/ maverick/universe Translation-en
Ign file:/home/user7/repository/ maverick/universe Translation-en_US
Ign file: maverick Release
Ign file: maverick/main i386 Packages
Ign file: maverick/restricted i386 Packages
Ign file: maverick/universe i386 Packages
Ign file: maverick/multiverse i386 Packages
Ign file: maverick/main i386 Packages
Ign file: maverick/restricted i386 Packages
Ign file: maverick/universe i386 Packages
Ign file: maverick/multiverse i386 Packages
Err file: maverick/multiverse i386 Packages
File not found
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en_US
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/restricted Translation-en
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/restricted Translation-en_US
E: Some index files failed to download, they have been ignored, or old ones used instead.
user7@user7-356HZM-S2:/$
That shows that web sources are no longer available.
To update reload the sources list package index:
user7@user7-356HZM-S2:/$ sudo apt-get update
See list of source addresses some of which may show error messages because they are not available.
To open and read the file called sources.list using Nano text editor:
user7@user7-356HZM-S2:/$ nano /etc/apt/sources.list
user7@user7-356HZM-S2:/$
deb cdrom:[Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)]/ maverick$
# Mount package source cdrom or DVD in root directory called /cdrom .
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
...etc
See Nano command options flags at bottom of page.
Press Control-x to exit the text editor and return to the Terminal command line. Generally use Gedit instead of Nano or Vi.
To list and show the contents of a folder or directory.
In following examples, directory and file names start with test, eg /testdog.
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public testdog
Clients Domes Pictures repository10 Transit
Desktop Downloads Programs Templates Videos
Subfolders are listed blue, executable files are green.
To show the contents of a Debian deb software package program:
user7@user7-356HZM-S2:~$ sudo dpkg -c ~/repository/gdebi_0.8.7_all.deb
drwxr-xr-x root/root 0 2012-11-03 03:40 ./
drwxr-xr-x root/root 0 2012-11-03 03:40 ./usr/
drwxr-xr-x root/root 0 2012-11-03 03:40 ./usr/bin/
... etc ...
drwxr-xr-x root/root 0 2012-11-03 03:40 ./usr/share/application-registry/
-rw-r--r-- root/root 163 2012-11-03 03:38 ./usr/share/application-registry/gdebi.applications
drwxr-xr-x root/root 0 2012-11-03 03:40/usr/share/man/man1/gdebi-gtk.1.gz
lrwxrwxrwx root/root 0 2012-11-03 03:40 ./usr/bin/gdebi-gtk -> ../share/gdebi/gdebi-gtk
user7@user7-356HZM-S2:~$
To change to a different directory, cd.
user7@user7-356HZM-S2:~$ cd ~/testdog
To open a new text file using Gedit:
user7@user7-356HZM-S2:~/testdog$ gedit testhound
user7@user7-356HZM-S2:~/testdog$ ls
testhound
To make a directory or folder.
user7@user7-356HZM-S2:~/testdog$ mkdir ~/testcats
To change to the home directory using a tild ~ :
user7@user7-356HZM-S2:~/testdog$ cd ~/
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public testcats Videos
Clients Domes Pictures repository10 testdog
Desktop Downloads Programs Templates Transit
To move a file from one directory to another.
user7@user7-356HZM-S2:~$ mv ~/testdog/testhound ~/testcats
user7@user7-356HZM-S2:~$ cd ~/testcats
user7@user7-356HZM-S2:~/testcats$ ls
testhound
To move a file from one directory to another.
user7@user7-356HZM-S2:~/testdog$ mv ~/testcats/testhound ~/testdog
user7@user7-356HZM-S2:~/testdog$ ls
testhound
user7@user7-356HZM-S2:~/testdog$
To open a new test file and call it testcat
user7@user7-356HZM-S2:~/testdog$ gedit ~/testcats/testcat
To rename a file
user7@user7-356HZM-S2:~/testdog$ mv testhound testhound2
user7@user7-356HZM-S2:~/testdog$ ls
testhound2
user7@user7-356HZM-S2:~/testdog$
Show current location in directory tree, where
user7@user7-356HZM-S2:~/testcats$ pwd
/home/user7/testcats
user7@user7-356HZM-S2:~/testcats$
Open or change to another folder or directory.
user7@user7-356HZM-S2:~/testdogs$ cd ~/testcats
user7@user7-356HZM-S2:~/testcats$
To rename a directory:
user7@user7-356HZM-S2:~/testcats$ mv ~/testdog /testdogs
mv: cannot create directory `/testdogs': Permission denied
user7@user7-356HZM-S2:~/testcats$ cd /
user7@user7-356HZM-S2:/$ mv ~/testdog ~/testdogs
user7@user7-356HZM-S2:/$ cd ~/
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public testcats Videos
Clients Domes Pictures repository10 testdogs
Desktop Downloads Programs Templates Transit
user7@user7-356HZM-S2:~$
To rename a subdirectory with move mv:
user7@user7-356HZM-S2:~/testdogs$ mv /Home/testdogs/wild /Home/testdogs/testwild
mv: cannot stat `/Home/testdogs/wild': No such file or directory
So check the name of the user.
user7@user7-356HZM-S2:/$ cd /home
user7@user7-356HZM-S2:/home$ ls
lost+found user7
user7@user7-356HZM-S2:/home$ cd /home/user7/
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public testcats Videos
Clients Domes Pictures repository10 testdogs
Desktop Downloads Programs Templates Transit
user7@user7-356HZM-S2:~$ mv /home/user7/testdogs/wild /home/user7/testdogs/testwild
user7@user7-356HZM-S2:~$ cd /home/user7/testdogs/
user7@user7-356HZM-S2:~/testdogs$ ls
testhound2 testwild
user7@user7-356HZM-S2:~/testdogs$
To copy and paste a file:
user7@user7-356HZM-S2:~$ cd /testdogs
bash: cd: /testdogs: No such file or directory
user7@user7-356HZM-S2:~$ cd /~/testdogs
bash: cd: /~/testdogs: No such file or directory
user7@user7-356HZM-S2:~$ cd /home/user7/testdogs
user7@user7-356HZM-S2:~/testdogs$ ls
testhound2 testwild
user7@user7-356HZM-S2:~/testdogs$ cp testhound2 testhound3
user7@user7-356HZM-S2:~/testdogs$ ls
testhound2 testhound3 testwild
user7@user7-356HZM-S2:~/testdogs$
To show what program packages are stored in the cache.
user7@user7-356HZM-S2:~$ ls /var/cache/apt/archives/
lock partial
user7@user7-356HZM-S2:~$ sudo gedit /var/cache/apt/archives/lock
[sudo] password for user7:
user7@user7-356HZM-S2:~$ ls /var/cache/apt/archives/partial
user7@user7-356HZM-S2:~$
No packages are in the cache. Open Synaptic preferences and choose to not automatically delete packages from the cache.
cp - To copy several files from one directory into another:
user@user-U-H:~/Desktop$ cp ./sshsh shtest ipdetect ./testfold/
There files called sshsh, shtest and ipdetect were copied from the current directory to a subdirectory called ./testfold/
user@user-U-H:~/Desktop$ ls ./testfold/
errors quailprice.png sshsh
ipdetect shtest Green Land.mp3
user@user-U-H:~/Desktop$
cat - To show, concatenate, what data is in several files one after the other:
cat ./testfold/ sshsh shtest ipdetect
user@user-U-H:~/Desktop$ cat ./testfold/ sshsh shtest ipdetect
cat: ./testfold/: Is a directory
Cat shows the contents of the three files one after another in the Terminal window.
... In this example, we want to make sure a certain file etc ...
Later they reported my IP address different.
www.proofpoint.com -
... etc
Incident ID: 449001100028204548-89902839584851685
user@user-U-H:~/Desktop$
To copy all the deb packages stored in the apt archives directory and paste them into a home ~/repository.
user7@user7-356HZM-S2:/$ sudo cp /var/cache/apt/archives/*.deb ~/repository
[sudo] password for user7:
cp: cannot stat `/var/cache/apt/archives/*.deb': No such file or directory
user7@user7-356HZM-S2:/$
The files have been cleared out of the cache archive; no debs to copy.
To copy a directory recursively use the cp -r option.
user7@user7-356HZM-S2:/$ cd ~
user7@user7-356HZM-S2:~$ mkdir ~/test
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public test
Clients Domes Pictures repository10 Transit
Desktop Downloads Programs Templates Videos
user7@user7-356HZM-S2:~$ cp ~/Transit ~/test
cp: omitting directory `/home/user7/Transit'
That means Terminal failed to copy because the -r option was missing from the command.
user7@user7-356HZM-S2:~$ cp -r ~/Transit ~/test
user7@user7-356HZM-S2:~$ cd ~/test
user7@user7-356HZM-S2:~/test$ ls
Transit
user7@user7-356HZM-S2:~/test$
To copy a group of files from one directory to another:
user7@user7-356HZM-S2:~/Desktop$ cd ~/repository
user7@user7-356HZM-S2:~/repository$ ls dpkg*
dpkg_1.15.8.4ubuntu3.1_i386.deb dpkg-dev.deb
dpkg_1.15.8.4ubuntu3_i386.deb dpkg-repack_1.32_all.deb
dpkg-cross_2.5.8ubuntu2_all.deb dpkg-repack_1.37_allb.deb
dpkg-dev_1.15.8.4ubuntu3_all.deb dpkg-repack_1.37_all.deb
dpkg-dev_1.16.18_all.deb dpkg-www_2.54+nmu1_all.deb
user7@user7-356HZM-S2:~/repository$ sudo cp ~/repository/dpkg-dev_1.15.8.4ubuntu3_all.deb dpkg-dev_1.16.18_all.deb dpkg-dev.deb /var/cache/apt/archives
user7@user7-356HZM-S2:~/repository$ ls /var/cache/apt/archives
dpkg-dev_1.15.8.4ubuntu3_all.deb dpkg-dev.deb partial
dpkg-dev_1.16.18_all.deb lock
user7@user7-356HZM-S2:~/repository$
To close down Terminal, quit and exit.
user7@user7-356HZM-S2:/$ exit
To delete, trash or remove rm a file.
user7@user7-356HZM-S2:~$ cd /home/user7/testdogs
user7@user7-356HZM-S2:~/testdogs$ ls
testhound2 testhound3 testwild
user7@user7-356HZM-S2:~/testdogs$ rm testhound2
user7@user7-356HZM-S2:~/testdogs$ ls
testhound3 testwild
user7@user7-356HZM-S2:~/testdogs$
To remove rmdir and delete or trash a directory.
user7@user7-356HZM-S2:~/testdogs$ rmdir testwild
user7@user7-356HZM-S2:~/testdogs$ ls
testhound3
user7@user7-356HZM-S2:~/testdogs$
Command options flags start with a - hyphen.
To show the contents of a directory line by line in detail, ls -l.
user7@user7-356HZM-S2:~/testdogs$ ls -l
total 4
-rw-r--r-- 1 user7 user7 20 2017-05-26 19:53 testhound3
user7@user7-356HZM-S2:~/testdogs$
The ls line above shows user7 as the owner of the file called testhound3, which has a size of 20 bytes and was last modified on May 26. The rw means the file can be read and written to. An x would mean the file was executable as a program. If the x was replaced by a hyphen then that would mean permission to execute the file had been revoked.
To change the security mode or accessibility of a file use command chmod. R, W, X and - are called security permissions or modes.
For help on chmod.
user7@user7-356HZM-S2:~/testdogs$ chmod --help
Usage: chmod [OPTION]... MODE[,MODE]... FILE...
or: chmod [OPTION]... OCTAL-MODE FILE...
or: chmod [OPTION]... --reference=RFILE FILE...
Change the mode of each FILE to MODE.
-c, --changes like verbose but report only when a change is made
--no-preserve-root do not treat `/' specially (the default)
--preserve-root fail to operate recursively on `/'
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
--reference=RFILE use RFILE's mode instead of MODE values
-R, --recursive change files and directories recursively
--help display this help and exit
--version output version information and exit
Each MODE is of the form `[ugoa]*([-+=]([rwxXst]*|[ugo]))+'.
Report chmod bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
For complete documentation, run: info coreutils 'chmod invocation'
user7@user7-356HZM-S2:~/testdogs$
To add + permission for any other o person user to execute x a file:
This file is called testhound3.
user7@user7-356HZM-S2:~/testdogs$ chmod o+x testhound3
user7@user7-356HZM-S2:~/testdogs$ ls -l
total 4
-rw-r--r-x 1 user7 user7 20 2017-05-26 19:53 testhound3
user7@user7-356HZM-S2:~/testdogs$
See the x and that Terminal has changed the file name from white to green.
To list across the line who owns a file and other details:
user7@user7-356HZM-S2:~$ ls -l ~/Desktop/linuxcomand
-rw-r--r-- 1 user7 user7 137015 2017-06-14 12:43 /home/user7/Desktop/linuxcomand
user7@user7-356HZM-S2:~$
So user user7 owns the file called linuxcomand.
To permit let other o users access and write w to a directory d.
user7@user7-356HZM-S2:~/Desktop$ chmod o+w libcp
user7@user7-356HZM-S2:~/Desktop$ ls -l
total 1544 ... etc
drwx------ 2 user7 user7 4096 2007-03-18 13:04 debfonts
-rw-r--r-- 1 user7 user7 1365896 2017-06-12 14:49 dpkg-dev_1.16.18_all.deb
drwx------ 2 user7 user7 4096 2007-03-18 13:08 gzpackages
drwx----w- 2 user7 user7 4096 2017-05-23 04:33 libcp
drwx------ 2 user7 user7 40960 2017-06-05
user7@user7-356HZM-S2:~/Desktop$
Others can now write w to the file the directory d called libcp, which contains executable x files. Terminal now highlights the directory name in green instead of blue. Only the owner of the other directories can write to them.
To secure a directory d so that other o users cannot access or write w to it, type a minus - :
user7@user7-356HZM-S2:~/Desktop$ chmod o-w libcp
user7@user7-356HZM-S2:~/Desktop$ ls -l
total 1544
drwx------ 2 user7 user7 4096 2007-03-18 13:04 debfonts ... etc ...
04:33 libcp
drwx------ 2 user7 user7 40960 2017-06-05 19:40 libpacks
-rw-r--r-- 1 user7 user7 137316 2017-06-14 12:58 linuxcomand
drwx------ 3 user7 user7 4096 2017-05-29 09:47 sudo
user7@user7-356HZM-S2:~/Desktop$
Only the owner of the directories, including libcp, can write to them.
To show what groups of users are using the operating system.
user7@user7-356HZM-S2:~$ groups
user7 adm dialout fax cdrom floppy tape audio dip video plugdev fuse netdev lpadmin admin sambashare
user7@user7-356HZM-S2:~$
So there is only one group, that of user7.
To show the pathway pw to the home directory d of the main user.
user7@user7-356HZM-S2:~$ pwd
/home/user7
user7@user7-356HZM-S2:~$
To change or go to the home directory of another user, type a tilde ~ to indicate home directory without a slash, and the name of the other user.
user7@user7-356HZM-S2:~$ cd ~tomt
user7@user7-356HZM-S2:/home/tomt$
To add a new user to the system:
user7@user7-356HZM-S2:~$ sudo adduser sally
[sudo] password for user7:
Adding user `sally' ...
Adding new group `sally' (1002) ...
Adding new user `sally' (1002) with group `sally' ...
Creating home directory `/home/sally' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Keep note of the password.
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for sally
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
user7@user7-356HZM-S2:~$
T logon or switch to another user's account:
user7@user7-356HZM-S2:~$ "su" sally
Password:
Added user sally.
sally@user7-356HZM-S2:/home/user7$
To logout from a user account to return to the administrator command line:
sally@user7-356HZM-S2:/home/user7$ exit
exit
user7@user7-356HZM-S2:~$
To change the password of a user:
sally@user7-356HZM-S2:/home/user7$ exit
exit
user7@user7-356HZM-S2:~$ sudo passwd sally
[sudo] password for user7:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
user7@user7-356HZM-S2:~$
To delete a user from the system:
user7@user7-356HZM-S2:~$ sudo userdel sally
user7@user7-356HZM-S2:~$
To search for find an unknown k or forgotten command in the Linux manuals by typing a key word:
Here the user has forgotten how to rename a file.
user7@user7-356HZM-S2:/$ man -k rename
dpkg-name (1) - rename Debian packages to full package names
mmove (1) - move or rename an MSDOS file or subdirectory
mren (1) - rename an existing MSDOS file
mv (1) - move (rename) files
prename (1) - renames multiple files
rename (1) - renames multiple files
rename (2) - change the name or location of a file
rename.ul (1) - Rename files
renameat (2) - rename a file relative to directory file descriptors
zipnote (1) - write the comments in zipfile to stdout, edit comments...
user7@user7-356HZM-S2:/$
See also the -rename command.
To quit, leave exit a user manual and return to the command prompt, press and hold shift key and colon, type q and press enter key, Shift/:q
To set up other users and groups, read linuxhow.txt.
To show the pathname of the home directory, pwd.
user7@user7-356HZM-S2:~/testdogs$ cd ~/
user7@user7-356HZM-S2:~$ pwd
/home/user7
user7@user7-356HZM-S2:~$
To copy cp a file from one directory to another.
user7@user7-356HZM-S2:~$ cd ~/testdogs
user7@user7-356HZM-S2:~/testdogs$ cp testhound3 ~/testcats
user7@user7-356HZM-S2:~/testdogs$ ls
testhound3
user7@user7-356HZM-S2:~/testdogs$ ls ~/testcats
testcat testhound3
user7@user7-356HZM-S2:~/testdogs$
Copy a file recursively from one directory to backup it in another directory.
user7@user7-356HZM-S2:~/test$ cp -r testfile ~/Transit
user7@user7-356HZM-S2:~/test$ cd ~/Transit
user7@user7-356HZM-S2:~/Transit$ ls
testfile
user7@user7-356HZM-S2:~/Transit$
A recursive -r command applied to the directory you are in and all its subdirectories, or from the directory you specify in the command and all its subdirectories.
To copy a file as a file with a different name.
user7@user7-356HZM-S2:~/test$ cp testfile testfile4
user7@user7-356HZM-S2:~/test$ ls
testfile testfile3 testfile4 transit2
To copy a file interactively -i so that you will be warned if any file in the destination directory has the same name as the file you are copying:
user7@user7-356HZM-S2:~/test$ ls
testfile testfile3 testfile4 transit2
user7@user7-356HZM-S2:~/test$ cp -i testfile ~/testdir2
cp: overwrite `/home/user7/testdir2/testfile'? n
user7@user7-356HZM-S2:~/test$
To overwrite the file, type y instead of n.
To copy a directory with all its files from one directory into another:
user7@user7-356HZM-S2:~/test$ ls
testfile testfile3 testfile4 transit2
user7@user7-356HZM-S2:/$ cp -R ~/test ~/testdir2
user7@user7-356HZM-S2:/$ ls ~/testdir2
test testfile
user7@user7-356HZM-S2:/$ ls ~/testdir2/test
testfile testfile3 testfile4 transit2
user7@user7-356HZM-S2:/$
To copy every file with a name beginning with tes from the working directory you are in to another directory, using a wildcard * :
user7@user7-356HZM-S2:~/test$ cp te* ~/testdir3
user7@user7-356HZM-S2:~/test$ ls ~/testdir3
testfile testfile3 testfile4
user7@user7-356HZM-S2:~/test$
To remove every file with a name beginning with tes from a directory, using a wildcar * :
user7@user7-356HZM-S2:~/test$ rm ~/testdir3/tes*
user7@user7-356HZM-S2:~/test$ ls
testfile testfile3 testfile4 transit2
user7@user7-356HZM-S2:~/test$ ls ~/testdir3
user7@user7-356HZM-S2:~/test$
To move all files from the working directory you are in to another directory, using a wildcard:
user7@user7-356HZM-S2:~/test$ ls ~/testdir3
user7@user7-356HZM-S2:~/test$ mv * ~/testdir3
user7@user7-356HZM-S2:~/test$ ls ~/testdir3
testfile testfile3 testfile4 transit2
user7@user7-356HZM-S2:~/test$
Notice that no tilde slash ~/ is used to indicate the working directory and that only one wildcard asterisk * is used.
To copy every file in the working directory you are in to another directory, using a wildcard:
user7@user7-356HZM-S2:~/test$ cd ~/testdir3
user7@user7-356HZM-S2:~/testdir3$ cp * ~/test
cp: omitting directory `transit2'
user7@user7-356HZM-S2:~/testdir3$ ls ~/test
testfile testfile3 testfile4
user7@user7-356HZM-S2:~/testdir3$
To show a list of all files in a directory which have the number 4 in their name, using two * asterisks.
user7@user7-356HZM-S2:~/testdir3$ cd ~/test
user7@user7-356HZM-S2:~/test$ ls
testfile testfile3 testfile4
user7@user7-356HZM-S2:~/test$ ls *4*
testfile4
user7@user7-356HZM-S2:~/test$
To remove, delete or empty all files from the current working directory you are in:
user7@user7-356HZM-S2:~/test$ ls
testfile testfile3 testfile4
user7@user7-356HZM-S2:~/test$ rm *
user7@user7-356HZM-S2:~/test$ ls
user7@user7-356HZM-S2:~/test$
To erase or remove rmdir an empty directory:
user7@user7-356HZM-S2:~$ rmdir ~/testcats
rmdir: failed to remove `/home/user7/testcats': Directory not empty
user7@user7-356HZM-S2:~$ rmdir ~/testdogs
rmdir: failed to remove `/home/user7/testdogs': Directory not empty
user7@user7-356HZM-S2:~$
user7@user7-356HZM-S2:~$ rmdir --help
Usage: rmdir [OPTION]... DIRECTORY...
Remove the DIRECTORY(ies), if they are empty.
--ignore-fail-on-non-empty
ignore each failure that is solely because a directory
is non-empty
-p, --parents remove DIRECTORY and its ancestors; e.g., `rmdir -p a/b/c' is
similar to `rmdir a/b/c a/b a'
-v, --verbose output a diagnostic for every directory processed
--help display this help and exit
--version output version information and exit
Report rmdir bugs to bug-coreutils@gnu.org
GNU coreutils home page:
General help using GNU software:
For complete documentation, run: info coreutils 'rmdir invocation'
user7@user7-356HZM-S2:~$
To recursively -r remove delete a directory and all the subdirectories and files within it.
user7@user7-356HZM-S2:~$ rm -r ~/testdogs
user7@user7-356HZM-S2:~$ rm -r ~/testcats
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public testcat2
Clients Domes Pictures repository10 Transit
Desktop Downloads Programs Templates Videos
user7@user7-356HZM-S2:~$ rm -r ~/testcat2
user7@user7-356HZM-S2:~$
To read about a command in the Linux user manual online, type the command man followed by the name of the command.
user7@user7-356HZM-S2:~$ man chmod
CHMOD(1) User Commands CHMOD(1)
NAME
chmod - change file mode bits
SYNOPSIS
chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...ION
This manual page documents the GNU version of chmod. chmod changes the
... etc
Tap the space bar to scroll down the page. To close the manual and go back to the command prompt, type q for quit.
To learn how to use the manual, run the command man man.
user7@user7-356HZM-S2:~$ man man
To search the online manual without knowing the name of a command, use the keyword option -k.
user7@user7-356HZM-S2:~$ man -k spell
aspell (1) - interactive spell checker
aspell-autobuildhash (8) - Autobuilding aspell hash files for some dicts
aspell-import (1) - import old personal dictionaries into GNU Aspell
enchant (1) - a spellchecker
ispell-autobuildhash (8) - Autobuilding the ispell hash file for some dicts
ispell-wrapper (1) - smart wrapper for ispell
...etc
user7@user7-356HZM-S2:~$ man enchant
ENCHANT(1) Enchant Mini Help File
NAME
Enchant - a spellchecker
SYNOPSIS
enchant [-a] [-l] [-L] [-v]
DESCRIPTION
Enchant is an ispell-compatible spellchecker.
OPTIONS
-a List alternatives.
-l List only the misspellings.
-L Include the line number in the output.
Press q to quit.
To close, exit or quit a manual, press q. Shift/:q enter.
Spell or Aspell or Ispell can be installed for Linux. See spellsudo.txt
To check the spelling of a word:
spell
ken@tomt-P5D3:~$ spell
oranje
oranje
orange
banana
^C
ken@tomt-P5D3:~$
Type the command spell and press enter.
Type the word to spell and enter.
If the word is spelled right, Spell will go to an empty line for another word.
If the word is wrong, Spell will repeat the wrong spelling for another try.
To check the spelling of every word in a text file:
spell filename
Change directories to one holding that file.
Run spell filename.
Spell will list the words spelled wrong.
To check spelling in a text file:
$ spell ~/Desktop/filename
Here the file is called ab1032.
username@loocalhost-id:~$ spell ~/Desktop/ab1032
wale
onionm
org
username@loocalhost-id:~$
That is three possible spelling errors.
To check the meaning or synonyms of a word, use the dictionary program called dict:
$ dict word
pete@pete-ID:~$ dict porridge
3 definitions found
From The Collaborative International Dictionary of English v.0.48 [gcide]:
Porridge \Por"ridge\, n. [Probably corrupted fr. pottage; perh.
influenced by OE. porree a kind of pottage, OF. porr['e]e,
fr. L. porrum, porrus, leek. See {Pottage}, and cf.
{Porringer}.]
A food made by boiling some leguminous or farinaceous
substance, or the meal of it, in water or in milk, making of
broth or thin pudding; as, barley porridge, milk porridge,
bean porridge, etc.
[1913 Webster]
From WordNet (r) 3.0 (2006) [wn]:
porridge
n 1: soft food made by boiling oatmeal or other meal or legumes
in water or milk until thick
From Moby Thesaurus II by Grady Ward, 1.0 [moby-thesaurus]:
90 Moby Thesaurus words for "porridge":
albumen, batter, bonnyclabber, breakfast food, butter, cataplasm,
cereal, clabber, cornflakes, cornstarch, cream, crush, curd, etc
pete@pete-ID:~$
To find the username of another person on the system:
Start the graphical program the system administrator users to manage users and groups of users.
user7@user7-356HZM-S2:/$ users-admin
To find and show the files in a subdirectory of the current directory. In this example, the current directory, indicated by a full stop, is Desktop and the subdirectory is debfonts.
user7@user7-356GZM-S2:~/Desktop$ find ./debfonts
./debfonts
./debfonts/fonts-linex_2.2-6_all.deb
./debfonts/ttf-linex_2.2-6_all.deb
./debfonts/ttf-linex_2.2-6_all2.deb
./debfonts/ttf-linux-libertine_5.1.3-1_all.deb
./debfonts/ttf-linux-libertine_5.1.3-1_all2.deb
user7@user7-356GZM-S2:~/Desktop$
To find a file or directory in the home directory or any of its subdirectories:
user7@user7-356HZM-S2:/$ find ~ -name 'test*'
Name is the filename or part of it. Tilde limits the search to home directories. Note that the name with a wildcard must be enclosed in single quotes.
user7@user7-356HZM-S2:/$ find ~ -name 'test*'
/home/user7/Desktop/sudo/testmicke1.ogg
/home/user7/Documents/testfax.odt
... etc
/home/user7/Programs/Repackages/testdisk_6.11-1_i386.deb
/home/user7/test
/home/user7/testdir2
/home/user7/testdir2/testfile
/home/user7/testdir2/test
/home/user7/testdir2/test/testfile
/home/user7/testdir2/test/testfile3
/home/user7/testdir2/test/testfile4
/home/user7/testdir3
user7@user7-356HZM-S2:/$
To find a file in the current directory:
user7@user7-356HZM-S2:~/testdir2$ find '.' -name testfile
./testfile
./test/testfile
user7@user7-356HZM-S2:~/testdir2$
Notice that the tild ~ has been replaced with '.' to limit the search to the current directory. The filename does not need quotes because it does not have a wildcard with it.
To find a file in a subdirectory, in this case a zip file:
user7@user7-356GZM-S2:~/Desktop$ find ./xmail/*.zip
./xmail/xmail-1.27.win32bin.zip
user7@user7-356GZM-S2:~/Desktop$
To find files and directories with this name, -i ignoring case, ignoring whether the name has a capital letter or not:
user7@user7-356GZM-S2:~/Desktop$ find -iname Mailutils
./mailutils
./mailutils/mailutils
./mailutils2/mailutils
user7@user7-356GZM-S2:~/Desktop$
To find any files in a directory which are not deb packages: -
Note the quote markes in this command.
user7@user7-356GZM-S2:~/Desktop$ find ~/Desktop/libpacks/ -not -name '*.deb'
/home/user7/Desktop/libpacks/
/home/user7/Desktop/libpacks/1gzno
user7@user7-356GZM-S2:~/Desktop$
To find any hidden files in a directory, files f which start with a full stop .
user7@user7-356GZM-S2:~$ find ~/repository -type f -name '.*'
No hidden files.
Find hidden subdirectories d.
user7@user7-356GZM-S2:~$ find ~/repository -type d -name '.*'
user7@user7-356GZM-S2:~$
No hidden directories.
To search for and find a file f in any directory or subdirectory ignoring i whether name has a capital letter or lower case:
user7@user7-356GZM-S2:/$ sudo find / -type f -iname Packages.gz
/home/user7/Desktop/gzpackages/Packages.gz
/home/user7/repository/Packages.gz
user7@user7-356GZM-S2:/$
To find in a directory a file containing a string of words:
user7@user7-356HZM-S2:~$ grep -ilR "words to find" /home/user7/Desktop
/home/user7/Desktop/linuxcomand
user7@user7-356HZM-S2:~$
The file called linuxcomand contains the words to find.
To show or print the contents of a file on screen in Terminal, use the command more.
user7@user7-356HZM-S2:~/testdir2$ more testfile
Just a test file to be removed.
user7@user7-356HZM-S2:~/testdir2$
To start and open a new text file:
user7@user7-356HZM-S2:~/testdir2$ gedit
user7@user7-356HZM-S2:~/testdir2$
Start typing in gedit text editor.
Save and close the editor.
To join, combine or concatenate two or more files and show or print them to screen together in Terminal, use the cat comand.
user7@user7-356HZM-S2:~/testdir2$ ls
test testfile testfile5
user7@user7-356HZM-S2:~/testdir2$ cat testfile testfile5
Just a test file to be removed.
Yet another test file to be removed.
user7@user7-356HZM-S2:~/testdir2$
To combine two files into a new file with a different name, type a > arrow before the new filename. If an old file with the same name as the new is in the directory, it will be overwritten by the new one.
user7@user7-356HZM-S2:~/testdir2$ cat testfile testfile5 > testfileb
user7@user7-356HZM-S2:~/testdir2$ ls
test testfile testfile5 testfileb
user7@user7-356HZM-S2:~/testdir2$ more testfileb
Just a test file to be removed.
Yet another test file to be removed.
user7@user7-356HZM-S2:~/testdir2$
To add the content of one file to the end of another file, type two >> arrows.
user7@user7-356HZM-S2:~/testdir2$ cat testfile testfile5 >> testfileb
user7@user7-356HZM-S2:~/testdir2$ more testfileb
Just a test file to be removed.
Yet another test file to be removed.
Just a test file to be removed.
Yet another test file to be removed.
user7@user7-356HZM-S2:~/testdir2$
To print a hard copy on a default printer.
user7@user7-356HZM-S2:~/testdir2$ lpr testfile
lpr: Error - no default destination available.
user7@user7-356HZM-S2:~/testdir2$
The printer is not connected to the computer.
To print a hard copy on a printer called by the systems administrator hp14.
user7@user7-356HZM-S2:~/testdir2$ lpr -P hp14 testfile
lpr: The printer or class was not found.
user7@user7-356HZM-S2:~/testdir2$
That printer is not connected to the computer.
To copy a directory and its contents and paste move the files into another directory: -
The recursive -r option is needed to copy cp directories folders.
user7@user7-356HZM-S2:~/testdir2$ cd ~
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public test Transit
Clients Domes Pictures repository10 testdir2 Videos
Desktop Downloads Programs Templates testdir3
user7@user7-356HZM-S2:~$ cp -r test Transit
user7@user7-356HZM-S2:~$ ls Transit
test testfile
user7@user7-356HZM-S2:~$
To see how much used and free disk df space is available on hard drives.
user7@user7-356HZM-S2:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb2 30759872 2670960 26526392 10% /
none 373732 288 373444 1% /dev
none 379356 388 378968 1% /dev/shm
none 379356 312 379044 1% /var/run
none 379356 0 379356 0% /var/lock
/dev/sdb3 207201920 52784372 143892212 27% /home
user7@user7-356HZM-S2:~$
This output information says that 10% of one hard disk drive device is already used up and 26 gigabytes of free space is still available to use, and 27% of the other hard drive is used, leaving 143 gb free.
This df output also shows that the first hard drive is mounted in the / root directory of the LInux tree and the second hard drive is mounted in the /home directory. So system directories and files are stored on the first 30 gb drive and home directories and files are stored on the separate second 207gb drive.
To list all hardware devices on the computer.
user7@user7-271GZM-S2:/$ cd /dev
user7@user7-271GZM-S2:/dev$ ls
agpgart fd0u820 ram11 sr0 tty35 ttyS0
autofs fd0u830 ram12 sr1 tty36 ttyS1
block full ram13 stderr tty37 ttyS2
bsg fuse ram14 stdin tty38 ttyS3
b1440 oldmem sdb tty25 tty57 vcsa4
fd0u1600 parport0 sdb1 tty26 tty58 vcsa5
fd0u1680 pktcdvd sdb2 tty27 tty59 vcsa6
fd0u1722 port sdb3 tty28 tty6 vcsa7
fd0u1743 ppp sg0 tty29 tty60 vga_arbiter
fd0u1760 psaux sg1 tty3 tty61 zero
... etc
scroll the list using the scroll bar at right.
user7@user7-271GZM-S2:/dev$
That list includes video cards vga, hard drives hd, cdrives dvd, floppy drive fd, usb stick, ram card, and so on.
To show and see how much space is free only on the hard drive which contains your home directories:
user7@user7-356HZM-S2:~$ df ~
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb3 207201920 52784508 143892076 27% /home
user7@user7-356HZM-S2:~$
To show in megabytes and gigabytes -h the filesystem disk space on mounted partitions:
user7@user7-356HZM-S2:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb2 30G 2.6G 26G 10% /
none 365M 288K 365M 1% /dev
none 371M 248K 371M 1% /dev/shm
none 371M 312K 371M 1% /var/run
none 371M 0 371M 0% /var/lock
/dev/sdb3 198G 51G 138G 27% /home
user7@user7-356HZM-S2:~$
To display how hard disk space is being used:
user7@user7-356HZM-S2:~$ du -h
488K ./Programs/debian/chimera
26M ./Programs/debian
...etc
181M ./Programs/Repackages
4.0K ./Programs/ubuntu10/repository/lock
4.0K ./Programs/ubuntu10/repository/partial
57M ./Programs/ubuntu10/repository
57M ./Programs/ubuntu10
1.2G ./Programs
56K ./repository
51G .
user7@user7-356HZM-S2:~$
To see how much RAM memory the computer has:
user7@user7-356HZM-S2:~$ free -m
total used free shared buffers cached
Mem: 740 667 73 0 111 247
-/+ buffers/cache: 308 432
Swap: 1905 0 1905
user7@user7-356HZM-S2:~$
That computer has a total of about 0.75GB of random access memory.
To delete or remove a directory which contains other directories or files, add the recursive option -r.
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public test Transit
Clients Domes Pictures repository10 testdir2 Videos
Desktop Downloads Programs Templates testdir3
user7@user7-356HZM-S2:~$ rm -r testdir3
user7@user7-356HZM-S2:~$ ls
Business Documents Music Public test Videos
Clients Domes Pictures repository10 testdir2
Desktop Downloads Programs Templates Transit
user7@user7-356HZM-S2:~$
To see what programs or processes are running on the computer and what is the PID number of each program.
user7@user7-356HZM-S2:~$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 2868 1680 ? Ss 07:47 0:00 /sbin/init
root 2 0.0 0.0 0 0 ? S 07:47 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 07:47 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S 07:47 0:00 [migration/0]
root 5 0.0 0.0 0 0 ? S 07:47 0:00 [watchdog/0]
...etc
user7 1417 0.0 0.7 19268 5864 ? S 07:49 0:00 /usr/lib/policy
user7 1419 0.0 2.2 154964 17104 ? Sl 07:49 0:03 gnome-panel
user7 1421 0.1 3.1 58592 24068 ? Sl 07:49 0:05 /usr/bin/compiz
user7 1422 0.0 2.6 200412 20436 ? Sl 07:49 0:03 nautilus
user7 1425 0.0 1.1 30944 8636 ? Sl 07:49 0:03 /usr/lib/vino/v
etc ...
user7 1602 0.0 1.9 167280 14460 ? Sl 07:50 0:04 gnome-terminal
user7 1603 0.0 1.5 72228 11804 ? Sl 07:50 0:00 update-notifier
... etc
user7 1984 0.0 0.1 4588 1080 pts/0 R+ 09:13 0:00 ps aux
user7@user7-356HZM-S2:~$
This information shows two users of the computer, user the person and root the Linux system itself. The command column indicates which programs are active in use. The PID column shows the ID of each program.
To stop, shutdown or kill an active program or process which is stalling or threatening to crash the system: -
Run the command ps aux as shown above to find the PID identity of the program then run the kill command as shown below to shut it down.
$ kill PID
Where PID is the number.
But notice above that the gnome program for example is running with several differend PID numbers.
Do not add the -9 option to shut the program down suddenly unless you are sure.
To use the kill command, you must indicate with a number which program in particular you want to stop. Kill does not just refer to the program you are working in.
To stop a stuck terminal command find out how specifically or use cursor to select file menu and close window. Then restart Terminal.
To reuse repeat the last command: -
user7@user7-356HZM-S2:~$ ls ~/Desktop
2Btested dpkgtrial libcp linuxcomand sourcesright usershell
debfonts gzpackages libpacks sourcelines sudo
Press the up arrow to show the last command.
Edit that command as needed.
user7@user7-356HZM-S2:~$ ls ~/Desktop/gzpackages
abs-guide.html.tar.gz fsarchiver-bin-0.3.0.tar.gz
anonymous_ftp_sites_list.txt.gz gecko-sharp2_0.11-3ubuntu4.8.04.1.diff.gz
freefont-otf-20120503.tar.gz xmovie-1.9.13-src.tar.bz2
user7@user7-356HZM-S2:~$
To open an interactive -i shell in which you can run terminal commands as a systems administrator:
user7@user7-356HZM-S2:/$ sudo -i
[sudo] password for user7:
root@user7-356HZM-S2:~#
Notice that the command line now ends in a # instead of a $.
After the # you do not type sudo before a command.
To run a sudo command without opening a shell, begin the command after the $ with sudo.
A command prompt in a root shell, for an administrator, ends with hash, #. A command prompt in a normal terminal window for both administrators and other users ends with a $ sign.
To set a different password for the administrator, the root user: open a root shell and type # sudo passwd
then type the new password+ twice and remember it.
root@user7-356HZM-S2:~# sudo passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@user7-356HZM-S2:~#
To allow another user to administer the computer system, type the command "sudo adduser sudo"
or "sudo adduser admin"
Users other than an administrator do not use the sudo command.
To exit quit or logout of a shell, run return and or exit.
root@user7-356HZM-S2:~# return
-bash: return: can only `return' from a function or sourced script
root@user7-356HZM-S2:~# exit
logout
user7@user7-356HZM-S2:/$
See that the command line now ends with a $.
To see a description of any command:
user7@user7-356HZM-S2:/$ type alias
alias is a shell builtin
user7@user7-356HZM-S2:/$
Alias is the command name in that example.
user7@user7-356HZM-S2:/$ type gedit
gedit is /usr/bin/gedit
user7@user7-356HZM-S2:/$
To open or change to a directory, cd.
user7@user7-356HZM-S2:~$ cd ~/Desktop
user7@user7-356HZM-S2:~/Desktop$
Leave a space between the $ or # prompt and the command and another space between the command and the directory. Commands are case sensitive; capital D for Desktop. The backstroke \ must be typed in a command although the forward stroke / is shown in a prompt line.
To clear all the previous command lines from the Terminal window.
user7@user7-356HZM-S2:/$ clear
user7@user7-356HZM-S2:/$
To remove or erase old commands altogether, exit Terminal and open a new terminal.
To look and find who can use the bash program in the /bin directory.
user7@user7-356HZM-S2:/$ ls -l /bin/bash
-rwxr-xr-x 1 root root 801808 2010-08-11 05:58 /bin/bash
user7@user7-356HZM-S2:/$
This tells who owns and runs the bash program and whether they can read, write and execute it.
To reboot the computer:
wae@wae-GCM-S2L:/$ sudo reboot
[sudo] password for user:
To show see the date on a calendar.
user7@user7-356HZM-S2:/$ cal
May 2017
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
user7@user7-356HZM-S2:/$
To show the date and time.
user7@user7-356HZM-S2:~/Desktop$ date
Sun May 28 09:03:40 EST 2017
user7@user7-356HZM-S2:~/Desktop$
To set date and time.
user7@user7-271GZM-S2:~$ date
Wed May 31 00:24:17 EST 2017
Highlight and copy the old date and time to the clipboard. Paste it into the next command line. Edit it as a sudo command with quote marks for the right date and time.
user7@user7-271GZM-S2:~$ sudo date -s "Wed May 31 08:48:17"
Wed May 31 08:48:17 EST 2017
user7@user7-271GZM-S2:~$ date
Wed May 31 08:48:31 EST 2017
user7@user7-271GZM-S2:~$
To check see date and time on hardware clock.
user7@user7-271GZM-S2:~$ sudo hwclock
[sudo] password for user7: type administrator password here
Tue 30 May 2017 02:50:39 PM EST -0.875337 seconds
user7@user7-271GZM-S2:~$
To reset that clock time, better to restart computer and enter BIOS setup.
To copy output from the screen into a text file:
command > filename
Here the command is to list what is in the directory called /bin then print it into a file called bintest on the Desktop.
ls -l /bin > ~/Desktop/bintest
user@user-H64C-ED4:~$ ls -l /bin > ~/Desktop/bintest
user@user-H64C-ED4:~$ ls ~/Desktop/bintest
/home/user/Desktop/bintest
Thee is the new file.
user@user-H64C-ED4:~$ gedit ~/Desktop/bintest.txt
user@user-H64C-ED4:~$
Here from the new file are some lines out of the output.
total 12976
-rwxr-xr-x 1 root root 1037528 Jun 25 2016 bash
-rwxr-xr-x 1 root root 31288 May 20 2015 bunzip2
-rwxr-xr-x 1 root root 1964536 Aug 19 2015 busybox
-rwxr-xr-x 1 root root 31288 May 20 2015 bzcat
lrwxrwxrwx 1 root root 6 Dec 19 11:24 bzcmp -> bzdiff
-rwxr-xr-
To move the cursor to the beginning of the line in Gedit, press the home key. To move the cursor to the end of a line in Gedit, press the end key. These keys do not work while you are searching for a key word. Then drag cursor or press esc key.
To compare two binary or text files to see whether they are the same:
user7@user7-356HZM-S2:~/Desktop$ cmp linuxcomand repositorylog
linuxcomand repositorylog differ: byte 1, line 1
The word differ tells that they are different.
user7@user7-356HZM-S2:~/Desktop$ cmp linoxtest linuxcomand
No output here shows that the two files have the same content.
user7@user7-356HZM-S2:~/Desktop$ rm linoxtest
user7@user7-356HZM-S2:~/Desktop$
To compare two text files, open each in separate Terminal windows, side by side. The diff command is too awkward and difficult to use.
To compare the difference diff in the content of two directories:
user7@user7-356HZM-S2:~/Desktop$ ls
HDDglite libcp linuxcomand repositorylog sudo
user7@user7-356HZM-S2:~/Desktop$ diff sudo libcp
Only in libcp: 1libcp
Only in sudo: aptfail
Only in sudo: apthow
Only in sudo: cdromapt.png
...etc
Only in libcp: libbrlttyxlx.so
Only in libcp: libbrlttyxsc.so
Only in libcp: libfakeroot-sysv.so
Only in sudo: Linuxb.txt
Only in sudo: linuxcomand
Only in sudo: linuxhow
Only in sudo: linux.txt
etc ...
Only in sudo: testmicke1.ogg
user7@user7-356HZM-S2:~/Desktop$
Diff is awkward if a directory compared contains many files.
To open and look in a directory which is only available to the root administrator superuser:
user7@user7-356HZM-S2:~$ cd /
user7@user7-356HZM-S2:/$ sudo -i
[sudo] password for user7:
root@user7-356HZM-S2:~# cd /media/apt/
root@user7-356HZM-S2:/media/apt# ls
root@user7-356HZM-S2:/media/apt#
That directory is empty.
ln - To make a link to a file:
ln filename linkname
user@user-K-ED4:~$ cd ~/Desktop/testfold
user@user-K-ED4:~/Desktop/testfold$ ls
fruitsale listcut.txt tdout testlist2 testlistk2
fruitsale2 listtest testlist testlistk
Here a link is made to a file called testlist.
user@user-K-ED4:~/Desktop/testfold$ ln testlist link1
user@user-K-ED4:~/Desktop/testfold$ ls
fruitsale link1 listtest testlist testlistk
fruitsale2 listcut.txt tdout testlist2 testlistk2
There is the link file called link1.
Look in the link file.
user@user-K-ED4:~/Desktop/testfold$ cat link1
Fruit
Apples are crisp.
Oranges are juicy.
Bananas taste nice when soft when ripe.
Melons are refreshing.
Lemons and limes are bitter.
user@user-K-ED4:~/Desktop/testfold$ cat testlist
Look in the original file and see that it shows the same list of fruit.
You can have many links to one file.
That was a hard link.
To make a shortcut soft or symbolic link, type an -s option.
user@user-K-ED4:~/Desktop/testfold$ ln -s testlist ~/Desktop/link2
Here the link is made in a different directory from the original file. See the link in the Desktop directory.
user@user-K-ED4:~/Desktop/testfold$ ls ~/Desktop
2DO linuxsudob4 quailtypes sudolocatedb
link2 testfold
user@user-K-ED4:~/Desktop/testfold$
To mark links among a long list of files:
ls -l
user@user-K-ED4:~/Desktop/testfold$ ls -l
total 44
-rw-rw-r-- 1 user user 147 Jun 5 14:51 fruitsale
-rw-rw-r-- 1 user user 147 Jun 5 15:30 fruitsale2
-rw-rw-r-- 2 user user 136 Jun 5 14:32 link1
-rw-rw-r-- 1 user user 37 Jun 5 11:40 listcut.txt
-rw-rw-r-- 1 user user 101 Jun 5 10:30 listtest
-rw-rw-r-- 1 user user 6756 May 31 22:16 tdout
-rw-rw-r-- 2 user user 136 Jun 5 14:32 testlist
-rw-rw-r-- 1 user user 130 Jun 5 14:48 testlist2
-rw-rw-r-- 1 user user 55 Jun 5 14:40 testlistk
-rw-rw-r-- 1 user user 55 Jun 5 14:41 testlistk2
user@user-K-ED4:~/Desktop/testfold$
Links are marked with a number 2 in the second column.
user@user-K-ED4:~/Desktop/testfold$ ls -l ~/Desktop
total 572
-rw-rw-r-- 1 user user 232 Jun 8 12:45 2DO
lrwxrwxrwx 1 user user 8 Jun 15 12:04 link2 -> testlist
-rw-rw-r-- 1 user user 267648 Jun 15 12:25 linuxsudob4
-rw-rw-r-- 1 user user 282041 Jun 14 16:28 poli14619.png
-rw-rw-r-- 1 user user 4924 Jun 13 08:39 quailtypes
-rwx------ 1 user user 1807 Mar 22 10:13 start-tor-browser.desktop
-rw-r--r-- 1 user user 9435 Jun 11 09:40 sudolocatedb
drwxrwxr-x 2 user user 4096 Jun 15 11:49 testfold
Here the soft link cannot be opened but it points to the original file called testlist.
user@user-K-ED4:~/Desktop/testfold$ cat testlist
Fruit
Apples are crisp.
Oranges are juicy.
Bananas taste nice when soft when ripe.
Melons are refreshing.
Lemons and limes are bitter.
user@user-K-ED4:~/Desktop/testfold
Hard links copy the original file. So to delete that file data fully, you would have to delete every copy in whatever directory it is in. Soft links are only a link to the original flie. So if the original is deleted, the soft links are left pointing to a file that is no longer there and cannot be opened. Those softlinks would have to be deleted wherever they were. Links can mess a filing system. Hard links are not usually made to directories because they can lose data. Soft links to directories can become messy.
To make a soft link from one directory to to another:
user@user-K-ED4:~/Desktop/testfold$ ln -s ~/Desktop ~/Desktop/testfold/dtop
Here a new link called dtop in the testfold directory leads to the Desktop.
user@user-K-ED4:~/Desktop/testfold$ ls ~/Desktop
2DO linuxsudob4 quailtypes sudolocatedb
link2 poli14619.png start-tor-browser.desktop testfold
There is the testfold directory in which the linkfold was made.
user@user-K-ED4:~/Desktop/testfold$ cd ~/Desktop
user@user-K-ED4:~/Desktop$ ls
2DO poli14619.png start-tor-browser.desktop testfold
linuxsudob4 quailtypes sudolocatedb
There is a subdirectory called testfold where the new symbolic link is.
user@user-K-ED4:~/Desktop$ ls ~/Desktop/testfold/
dtop fruitsale2 listcut.txt tdout testlist2 testlistk2
fruitsale link1 listtest testlist testlistk
There is the link called dtop.
In File Manager, click the folder with the arrow on it in /testfold and you will see the icons or list of the files on the desktop.
To find any file in /testfold with a name which starts with list and ends with t and has any three letters in between, use a question ? wildcard.
user@user-K-ED4:~$ ls ~/Desktop/testfold/list???t
/home/user/Desktop/testfold/listtest
To find in a directory any file with a name which starts with fruit and ends with any number from 0 to 9, show a range of numbers in square brackets:
user@user-K-ED4:~$
user@user-K-ED4:~$ ls ~/Desktop/testfold/fruit*[0-9]
/home/user/Desktop/testfold/fruitsale2
user@user-K-ED4:~$
That used the brackets as wildcards. The brackets can instead hold a range of letters.
less - To show and scroll a document of many pages, use the less command.
less /path/filename
user@user-K-ED4:~$ less ~/Desktop/quailtypes
Press the page up, page down and up and down arrow keys to scroll the document. Press q or :q to quit and exit the document.
To logout leave the root # command prompt and return to the user $ command prompt.
root@user7-356HZM-S2:/media/apt# exit
logout
user7@user7-356HZM-S2:/$
To lookup find dig for the DNS domain name server information of a website.
user7@user7-356HZM-S2:~$ dig www.lycros.com
;; Warning: query response not set
; <<>> DiG 9.7.1-P2 <<>> www.lycros.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 24260
;; flags: aa rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;www.lycros.com. IN A
;; Query time: 2 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Sun May 28 20:44:53 2017
;; MSG SIZE rcvd: 32
user7@user7-356HZM-S2:~$
To find out about a program and how to use it:
In this example the program is called ldconfig.
user7@user7-356HZM-S2:~$ libtool
The program 'libtool' is currently not installed. You can install it by typing:
sudo apt-get install libtool
user7@user7-356HZM-S2:~$ sudo libtool
[sudo] password for user7:
sudo: libtool: command not found
user7@user7-356HZM-S2:~$ ldconfig
/sbin/ldconfig.real: Can't create temporary cache file /etc/ld.so.cache~: Permission denied
user7@user7-356HZM-S2:~$ sudo ldconfig
user7@user7-356HZM-S2:~$ sudo ldconfig -h
/sbin/ldconfig.real: invalid option -- 'h'
Try `ldconfig.real --help' or `ldconfig.real --usage' for more information.
user7@user7-356HZM-S2:~$ ldconfig.real --usage
Usage: ldconfig.real [-ilnNpvX?V] [-c FORMAT] [-C CACHE] [-f CONF] [-r ROOT]
[--format=FORMAT] [--ignore-aux-cache] [--print-cache] [--verbose]
[--help] [--usage] [--version]
user7@user7-356HZM-S2:~$
To read or edit the repository.conf file in /etc directory.
user7@user7-356HZM-S2:/$ sudo gedit /etc/repository.conf
Conf file opens in gedit.
user7@user7-356HZM-S2:/$
To read a manual about editing the sources list for a local repository.
user7@user7-356HZM-S2:~$ man sources.list
Press down arrow key to scroll manual.
SOURCES.LIST.D
The /etc/apt/sources.list.d directory provides a way to add
sources.list entries in separate files. The format is the same as for
the regular sources.list file. File names need to end with .list and
may only contain letters (a-z and A-Z), digits (0-9), underscore (_),
hyphen (-) and period (.) characters. Otherwise they will be silently
ignored.
The format for a sources.list entry using the deb and deb-src types is:
deb uri distribution [component1] [component2] [...]
URI SPECIFICATION
The currently recognized URI types are cdrom, file, http, ftp, copy,
ssh, rsh.
file
The file scheme allows an arbitrary directory in the file system to
be considered an archive. This is useful for NFS mounts and local
mirrors or archives.
cdrom
The cdrom scheme allows APT to use a local CDROM drive with media
swapping. Use the apt-cdrom(8) program to create cdrom entries in
the source list.
EXAMPLES
Uses the archive stored locally (or NFS mounted) at /home/jason/debian
for stable/main, stable/contrib, and stable/non-free.
deb file:/home/jason/debian stable main contrib non-free
As above, except this uses the unstable (development) distribution.
deb file:/home/jason/debian unstable main contrib non-free
Source line for the above
deb-src file:/home/jason/debian unstable main contrib non-free
To close manual, press esc escape key and file menu close Terminal window.
Dpkg-scanpackages is part of the dpky-dev package which dpkg installs. It generates the packages.gz file needed for offline repositories.
dpkg - To scan packages in a repository and make an index file called Packages.gz for apt-get:
Dpkg-dev needs to be installed as it includes the scanpackages program.
user7@user7-356GZM-S2:~/Desktop$ cd ~/repository
user7@user7-356GZM-S2:~/repository$ sudo dpkg-scanpackages ~/repository
dpkg-scanpackages: warning: Package apt (filename /home/user7/repository/apt_0.8.3ubuntu7_i386.deb) is repeat;
dpkg-scanpackages: warning: ignored that one and using data from /home/user7/repository/apt_0.8.3ubuntu7.3_i386.deb!
dpkg-scanpackages: warning: Package aptdaemon (filename /home/user7/repository/aptdaemon_0.31+bzr506-0ubuntu6.1_all.deb) is repeat but newer version;
dpkg-scanpackages: warning: used that one and ignored data from /home/user7/repository/aptdaemon_0.31+bzr506-0ubuntu2_all.deb!
... etc
ibkipi8_4.7.4-0ubuntu0.1_i386.deb) is repeat but newer version;
dpkg-scanpackages: warning: used that one and ignored data from /home/user7/repository/libkipi8_4.7.1-0ubuntu2_i386.deb!
dpkg-scanpackages: warning: Package libkipi-dbg (filename /home/user7/repository/libkipi-dbg_4.7.4-0ubuntu0.1_i386.deb) is repeat but newer version;
dpkg-scanpackages: warning: used that one and ignored data from /home/user7/repository/libkipi-dbg_4.7.1-0ubuntu2_i386.deb!
dpkg-deb: `/home/user7/repository/libuniconf4.6_4.6.1-2build1_i386.deb' is not a debian format archive
dpkg-scanpackages: error: couldn't parse control information from /home/user7/repository/libuniconf4.6_4.6.1-2build1_i386.deb.
user7@user7-356GZM-S2:~/repository$
To find the location of an executable program or whether it is installed, type which programname.
user7@user7-356HZM-S2:~$ which apt
user7@user7-356HZM-S2:~$ which apt-get
/usr/bin/apt-get
user7@user7-356HZM-S2:~$ apt
The program 'apt' is currently not installed. You can install it by typing:
sudo apt-get install openjdk-6-jdk
user7@user7-356HZM-S2:~$
That shows that the program apt is not installed but the program apt-get is installed in the directory /usr/bin/apt-get.
To list executable programs. Ubuntu stores them in /usr/bin directory.
Expand the terminal window to full screen view for a long list. Add an -m option to show the files across lines with commas.
user7@user7-356HZM-S2:/$ ls -m /usr/bin
[ foomatic-rip mclasserase sdiff
2to3 foomatic-searchprinter mcomp sdptool
2to3-2.6 free mcookie seahorse
a2p fribidi mcopy seahorse-daemon
aconnect from mc-tool see
ac ... etc
foomatic-ppdfile mbadblocks scrollkeeper-update zsoelim
foomatic-ppd-options mcat sctp_darn
foomatic-ppd-to-xml mcd sctp_status
foomatic-printjob mcheck sctp_test
user7@user7-356HZM-S2:/$ ls /usr/bin
Scroll the list.
To list show hidden files, those starting with a full stop . , as well as the other files in a directory:
user7@user7-356HZM-S2:/sys/firmware$ ls
acpi memmap
user7@user7-356HZM-S2:/sys/firmware$ ls -a
. .. acpi memmap
user7@user7-356HZM-S2:/sys/firmware$
Apt-get program package manager is installed with Ubuntu 10 but Aptitude is not. So use apt-get instead of aptitude as they do much the same thing.
To display a list of all aptitude-based packages distributions.
user7@user7-356HZM-S2:/sys/firmware$ dpkg -l
ii libxvmc1 2:1.0.5-1ubunt X11 Video extension library
ii libxxf86dga1 2:1.1.1-2 X11 Direct Graphics Access extension library
ii libxxf86vm1 1:1.1.0-2 X11 XFree86 video mode extension library
ii libzephyr4 3.0-1 Project Athena's notification service - non-
ii light-themes 0.1.8.3 Light Themes
ii linux-firmware 1.38.10 Firmware for Linux kernel drivers
ii linux-generic 2.6.35.32.42 Complete Generic Linux kernel
ii etc ...
ii xserver-xorg-v 1:1.2.4-0ubunt X.Org X server -- Voodoo display driver
ii xsltproc 1.1.26-6 XSLT 1.0 command line processor
ii xterm 261-1ubuntu3 X terminal emulator
ii xul-ext-ubufox 0.9.4-0ubuntu0 Ubuntu-specific configuration defaults and a
ii xulrunner-1.9. 1.9.2.28+build XUL + XPCOM application runner
ii xz-utils 4.999.9beta+20 XZ-format compression utilities
ii yelp 2.30.1-0ubuntu Help browser for GNOME
ii zenity 2.32.0-0ubuntu Display graphical dialog boxes from shell sc
ii zip 3.0-3 Archiver for .zip files
ii zlib1g 1:1.2.3.4.dfsg compression library - runtime
user7@user7-356HZM-S2:/sys/firmware$
To check see show whether a package is installed:
This example shows that a package called dpkg-dev has been uninstalled.
user7@user7-356HZM-S2:~$ sudo dpkg -s dpkg-dev
Package: dpkg-dev
Status: deinstall ok config-files
Priority: optional
Section: utils
Installed-Size: 1590
Origin: debian
Maintainer: Dpkg Developers
Bugs: debbugs://bugs.debian.org
Architecture: all
... etc
Homepage: http://wiki.debian.org/Teams/Dpkg
user7@user7-356HZM-S2:~$
To list show the locations of files to be installed to the system from a software package.
user7@user7-356HZM-S2:~$ sudo dpkg -L dpkg-dev
[sudo] password for user7:
/etc
/etc/dpkg
/etc/dpkg/shlibs.default
/etc/dpkg/shlibs.override
user7@user7-356HZM-S2:~$
To list all the files which were installed in a program package and their locations. In this example, the program is named python.
user7@user7-356HZM-S2:~$ sudo dpkg -L python
/.
/usr
/usr/bin
/usr/bin/dh_python2
/usr/share
/usr/share/debhelper
/usr/share/debhelper/autoscripts
/
... ets
/usr/lib
/usr/lib/valgrind
/usr/lib/valgrind/python.supp
/usr/bin/pyversions
/usr/bin/2to3
/usr/bin/pygettext
etc ...
are/doc/python2.6/python-policy.sgml.gz
/usr/share/doc/python2.6/python-policy.txt.gz
/usr/share/man/man1/pygettext.1.gz
/usr/share/man/man1/pdb.1.gz
/usr/share/man/man1/pydoc.1.gz
user7@user7-356HZM-S2:~$
To list a group of deb packages by using a keyword and a wildcard asterisk:
Change to the repository directory.
user7@user7-356HZM-S2:~/repository$ ls apt*
apt_0.8.3ubuntu7.3_i386.deb aptoncd_0.1.98+bzr117-1_all.deb
apt_0.8.3ubuntu7_i386.deb apt-src_0.25.1-0.1_all.deb
aptdaemon_0.31+bzr506-0ubuntu2_all.deb apturl_0.4.1ubuntu7.1_i386.deb
aptdaemon_0.31+bzr506-0ubuntu6.1_all.deb apturl-common_0.4.1ubuntu7.1_i386.deb
aptitude_0.6.3-2ubuntu4_i386.deb apt-xapian-index_0.39ubuntu1_all.deb
aptitude-doc-en_0.6.3-2ubuntu4_all.deb
user7@user7-356HZM-S2:~/repository$
To list all the packages in the repository which start with a particular letter:
user77@user77-356HZM-S2:~/repository$ ls a*
apt_0.8.3ubuntu7.3_i386.deb aptoncd_0.1.98+bzr117-1_all.deb
apt_0.8.3ubuntu7_i386.deb apt-src_0.25.1-0.1_all.deb
aptdaemon_0.31+bzr506-0ubuntu2_all.deb apturl_0.4.1ubuntu7.1_i386.deb
aptdaemon_0.31+bzr506-0ubuntu6.1_all.deb apturl-common_0.4.1ubuntu7.1_i386.deb
aptitude_0.6.3-2ubuntu4_i386.deb apt-xapian-index_0.39ubuntu1_all.deb
aptitude-doc-en_0.6.3-2ubuntu4_all.deb
user77@user77-356HZM-S2:~/repository$
To read a brief description of what a program does, browse to https://www.debian.org/distrib/packages, scroll to search package directories, type the name of the program package into the search field and select descriptions.
To check whether a software package can be installed without errors, conflicts or breaks:
user7@user7-356HZM-S2:/$ sudo apt-get --simulate install dpkg-dev
[sudo] password for user7:
Reading package lists... Done
Building dependency tree
Reading state information... Done
dpkg-dev is already the netomt version.
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
dpkg-dev : Depends: patch but it is not going to be installed
Recommends: build-essential but it is not going to be installed
Recommends: fakeroot but it is not going to be installed
Recommends: libalgorithm-merge-perl but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
user7@user7-356HZM-S2:/$
To remove uninstall a program package.
user7@user7-356HZM-S2:~$ sudo dpkg -r lilypond-data
(Reading database ... 128022 files and directories currently installed.)
Removing lilypond-data ...
/var/lib/dpkg/info/lilypond-data.postrm: 20: kpsewhich: not found
dpkg: error processing lilypond-data (--remove):
subprocess installed post-removal script returned error exit status 127
Errors were encountered while processing:
lilypond-data
user7@user7-356HZM-S2:~$
Lilypond-data package is broken, hard to remove.
To uninstall remove a software package:
sudo apt-get remove softwarename
user7@user7-356HZM-S2:/$ sudo apt-get remove mines
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mines
Find the right name for the program to be removed.
user7@user7-356HZM-S2:/usr$ ls
bin games include lib local sbin share src
user7@user7-356HZM-S2:/usr$ cd /usr/games
user7@user7-356HZM-S2:/usr/games$ ls
gbrainy gnome-sudoku gnomine mahjongg quadrapassel sol
user7@user7-356HZM-S2:/usr/games$ sudo apt-get remove gnomine
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
gnomine
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 3,269kB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 127432 files and directories currently installed.)
Removing gnomine ...
Processing triggers for gconf2 ...
Processing triggers for hicolor-icon-theme ...
Processing triggers for desktop-file-utils ...
Processing triggers for python-gmenu ...
Rebuilding /usr/share/applications/desktop.en_US.utf8.cache...
Processing triggers for man-db ...
Processing triggers for python-support ...
user7@user7-356HZM-S2:/usr/games$
To echo text output from Terminal to a text file in Gedit:
The file in this example is called 2do.
In Terminal, open a new text file.
user7@user7-356HZM-S2:~$ gedit ~/Desktop/2do
Gedit shows an new empty file.
Still in terminal,
user7@user7-356HZM-S2:~$ echo 'List here notes, reminders and things to do.' >> ~/Desktop/2do
Enclose text in quote marks ' and type two arrow marks >> to add the latest entry to earlier entries.
user7@user7-356HZM-S2:~$ echo 'In Gedit, delete old entries when finished with them.' >> ~/Desktop/2do
That line will show in the text file.
user7@user7-356HZM-S2:~$
In Gedit, click the screen and reload to see the latest entries then save the file.
To show a comprehensive general list of the commands which can be used in Terminal:
user7@user7-356HZM-S2:~$ compgen -c
see list
...ets
which
chmod
dd
sed
zmore
bzcmp
netstat
busybox
sleep
true
dash
setfont
unicode_start
lessecho
bunzip2
fgconsole
zegrep
run-parts
ed
mahjongg
sol
quadrapassel
gnomine
gnome-sudoku
gbrainy
user7@user7-356HZM-S2:~$
To open the CDrom drive tray:
user7@user7-271GZM-S2:~/Documents$ eject
user7@user7-271GZM-S2:~/Documents$
Put CD disk into open tray.
To see info about the CD rom drive:
sudo hdparm
eg sudo hdparm -I /dev/cdrom
ATAPI CD-ROM, with removable media
Model Number: _NEC DVD_RW ND-6750A
Serial Number:
Firmware Revision: 2.42
To unmount umount a CDrom from one directory and mount it to another directory:
user7@user7-356HZM-S2:/$ sudo umount /dev/sr0 /media/cdrom
umount: /dev/sr0: not mounted
umount: /media/cdrom: not mounted
user7@user7-356HZM-S2:/$ sudo mount /dev/sr0 /media/apt/
user7@user7-356HZM-S2:/$
Remounting the Ubuntu CD at /media/apt may help the apt program to find it. Use apt-cdrom add .Mount command automatically updates the /etc/mtab file to show the system where the drive is currently cd mounted.
To read where drives are mounted, change to /etc and gedit mtab.
user7@user7-356HZM-S2:/etc$ gedit mtab
user7@user7-356HZM-S2:/etc$
/dev/sdb2 / ext4 rw,errors=remount-ro,commit=0 0 0
proc /proc proc rw,noexec,nosuid,nodev 0 0
none /sys sysfs rw,noexec,nosuid,nodev 0 0
fusectl /sys/fs/fuse/connections fusectl rw 0 0
none /sys/kernel/debug debugfs rw 0 0
none /sys/kernel/security securityfs rw 0 0
none /dev devtmpfs rw,mode=0755 0 0
none /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
none /dev/shm tmpfs rw,nosuid,nodev 0 0
none /var/run tmpfs rw,nosuid,mode=0755 0 0
none /var/lock tmpfs rw,noexec,nosuid,nodev 0 0
/dev/sdb3 /home ext2 rw 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,noexec,nosuid,nodev 0 0
gvfs-fuse-daemon /home/user7/.gvfs fuse.gvfs-fuse-daemon rw,nosuid,nodev,user=user7 0 0
/dev/sr0 /media/disk iso9660 ro,nosuid,nodev,uhelper=udisks,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500 0 0
See there that a CD device /dev/sr0 is mounted in directory /media/disk.
To unmount the Ubuntu CD disk from the home ~/media directory and mount it in the root /cdrom/ directory where APT and Symantic user7@user7-356HZM-S2:/$ sudo cp /var/cache/apt/archives/*.deb ~/repository
[sudo] password for user7:
cp: cannot stat `/var/cache/apt/archives/*.deb': No such file or directory
user7@user7-356HZM-S2:/$ expect to find it.
user7@user7-356HZM-S2:~$ cd /
user7@user7-356HZM-S2:/$ sudo umount /dev/sr0 /media
[sudo] password for user7:
umount: /dev/sr0: not mounted
umount: /media: not mounted
user7@user7-356HZM-S2:/$ sudo mnt /dev/sr0 /cdrom/
sudo: mnt: command not found
user7@user7-356HZM-S2:/$ sudo mount /dev/sr0 /cdrom/
user7@user7-356HZM-S2:/$
To list hard drives and partitions, cdrom, floppy of the computer system:
user7@user7-356HZM-S2:/etc$ sudo fdisk -l
[sudo] password for user7:
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 13867 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00061d21
Device Boot Start End Blocks Id System
/dev/sda1 1 244 1951744 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2 * 244 4134 31250432 83 Linux
/dev/sda3 4134 13868 123086848 83 Linux
Disk /dev/sdb: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00005e97
Device Boot Start End Blocks Id System
/dev/sdb1 1 304 2440192 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/sdb2 * 304 4195 31250432 83 Linux
/dev/sdb3 4195 30402 210506752 83 Linux
user7@user7-356HZM-S2:/etc$
To show and edit a description of files systems in the the file called fstab:
user7@user7-356HZM-S2:/etc$ gedit fstab
user7@user7-356HZM-S2:/etc$
# /etc/fstab: static file system information.
# Use ' -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda2 during installation
UUID=182ec4bc-24c0-4354-b468-2b21028bcb7d / ext4 errors=remount-ro 0 1
# /home was on /dev/sda3 during installation
UUID=34294ce5-c220-4110-863b-7a32ee2862d8 /home ext2 defaults 0 2
/dev/sda1 none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8
That shows the system hard drive sda2 mounted at root /
the user hard drive sda3 mounted at in the /home directory
a floppy drive fp mounted at /media/floppy0
and a hard drive swap partition device /dev/sda1 .
Linux operating systems often mount drives to mount points in the /mnt directory.
To backup copy a file before editing it:
user7@user7-356HZM-S2:/etc$ sudo cp /etc/fstab /etc/fstab.bak
To show the UUID universal unique identity number of a file system device:
user7@user7-356HZM-S2:/$ sudo blkid /dev/sda1
[sudo] password for user7:
/dev/sda1: UUID="0dccb62c-277f-4777-8bbb-46949c410c5f" TYPE="swap"
user7@user7-356HZM-S2:/$
To list all the identity numbers UUIDs of a system.
user7@user7-356HZM-S2:/etc$ sudo blkid
/dev/sda1: UUID="0dccb62c-277f-4777-8bbb-46949c410c5f" TYPE="swap"
/dev/sda2: UUID="706f7fc6-1283-4217-a162-8f5d08b0a477" TYPE="ext4"
/dev/sda3: UUID="259b6c4a-fa35-4785-94d1-6799f7a731ec" TYPE="ext2"
/dev/sdb1: UUID="209eed6a-02d4-47d8-83dc-e64cfb93088f" TYPE="swap"
/dev/sdb2: UUID="182ec4bc-24c0-4354-b468-2b21028bcb7d" TYPE="ext4"
/dev/sdb3: UUID="34294ce5-c220-4110-863b-7a32ee2862d8" TYPE="ext2"
user7@user7-356HZM-S2:/etc$
To find out more about a website:
user7@user7-356HZM-S2:~$ dig -h | more
Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}
{global-d-opt} host [@local-server] {local-d-opt}
[ host [@local-server] {local-d-opt} [...]]
Where: domain is in the Domain Name System
q-class is one of (in,hs,ch,...) [default: in]
q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]
(Use ixfr=version for type ixfr)
q-opt is one of:
-x dot-notation (shortcut for reverse lookups)
-i (use IP6.INT for IPv6 reverse lookups)
-f filename (batch mode)
... etc
Press space bar to show more dig options.
To show print on screen kernel and driver messages
user7@user7-356HZM-S2:~$ dmesg
Much information.
To eject a CD or DVD disk from the drive.
First unmount umount the disk.
user7@user7-356HZM-S2:~$ eject
user7@user7-356HZM-S2:~$
Remove the disk and close the drive tray.
To display show echo a message on screen when scripting,
~$ echo whatever I type
whatever I type
Partition hard drive:
#cfdisk, see menu, 1gb for operating system, plus b4 mb swap partition, use Linux fdisk or cfdisk -
tag partition - t or w enter 83 for native Linux or 82 for Linux swap
create partition - n and w
default partition is /dev/hda
specify a different partition - # cfdisk /dev/hdb, or hdc
make swap partition - #cfdisk mkswap
activate swap partition - #cfdisk swapon
check partition table - fdisk - L
format swap file - #mkswap /dev/hdb2 #sync
activate swap partition - # swapon /dev/hdb2
or to partition hard disk:
#fdisk, see menu
# L # c for Win95 FAST32 LBA
DOS compatible flag is set, # n, # p for primary partition, 1 + type a number of cylinders
show partition info - p enter, print to screen
see /dev/hds1 Id83 Linux native etc
save partition - w enter
To install Linux: -
addswap linux recognises DOS
target partitions follow
source + CDROM
select install
configure
leave setup - exit
select source media - #
log in to setup - type # root
Slackware
Sudo -i and sudo -s do not work in Slackware
type command works differently for Ubuntu and Slackware
ESC, vi, :, q! enter. See slackware.txt.
To find what library lib and other dependencies are needed by an uninstalled deb package program in a repository directory.
user7@user7-356HZM-S2:~/repository$ dpkg -I apt_0.8.3ubuntu7.3_i386.deb
new debian package, version 2.0.
size 2082082 bytes: control archive= 8066 bytes.
74 bytes, 3 lines conffiles
1005 bytes, 22 lines control
16819 bytes, 225 lines md5sums
1131 bytes, 46 lines * postinst #!/bin/sh
553 bytes, 27 lines * postrm #!/bin/sh
1116 bytes, 32 lines * preinst #!/bin/sh
31 bytes, 1 lines shlibs
Package: apt
Priority: important
Section: admin
Installed-Size: 5968
Maintainer: Ubuntu Developers
Architecture: i386
Version: 0.8.3ubuntu7.3
Replaces: manpages-pl (<< 20060617-3~)
Provides: libapt-pkg4.10
Depends: libc6 (>= 2.8), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.4.0), zlib1g (>= 1:1.1.4)
Recommends: ubuntu-keyring, gpg
Suggests: aptitude | synaptic | wajig, dpkg-dev, apt-doc, bzip2, lzma, python-apt
Conflicts: python-apt (<< 0.7.93.2~)
Description: Advanced front-end for dpkg
This is Debian's next generation front-end for the dpkg package manager.
It provides the apt-get utility and APT dselect method that provides a simpler, safer way to install and upgrade packages. .
APT features complete installation ordering, multiple source capability
and several other unique features, see the Users Guide in apt-doc. .
(Repackaged on Fri, 29 Aug 2014 12:22:29 +1000 by dpkg-repack.)
Original-Maintainer: APT Development Team
user7@user7-356HZM-S2:~/repository$
To list ls display library files.
Actual library lib files are installed in the /usr/lib dir and have names starting with lib and ending not with .a or .so.
First expand the Terminal window to full screen to show the whole list. The run this command.
user7@user7-356HZM-S2:~$ ls /usr/lib
alsa-lib libexif.so.12 libieee1284.so.3.2.2 libSM.so.6.0.1
apt libexif.so.12.3.1 libieee.a libsndfile.so.1
aspell libexiv2.so.6 libijs-0.35.so libsndfile.so.1.0.21
at-spi libexiv2.so.6.0.0 libimobiledevice.so.1 libsnmp.so.15
avahi libexslt.so.0 libimobiledevice.so.1.0.1 libsnmp.so.15.1.2
bl etc ...
libevview.so.3.0.0 libiec61883.so.0 libsmpeg-0.4.so.0 xulrunner-addons
libexempi.so.3 libiec61883.so.0.1.1 libsmpeg-0.4.so.0.1.4 xvmcconfig-standard
libexempi.so.3.2.1 libieee1284.so.3 libSM.so.6
user7@user7-356HZM-S2:~$
Scroll.
To see if any deb packages of programs already installed are left in the cache.
user7@user7-356HZM-S2:~$ cd /var/cache/apt/archives
user7@user7-356HZM-S2:/var/cache/apt/archives$ ls
lock partial
user7@user7-356HZM-S2:/var/cache/apt/archives$ cd /var/cache/apt/archives/partial
user7@user7-356HZM-S2:/var/cache/apt/archives/partial$ ls
user7@user7-356HZM-S2:/var/cache/apt/archives/partial$
The cash archive has been cleared, probably automatically by APT.
Directories are shown by a forward slash like ~/.
To return to a new command prompt after typing a \ backstroke by mistake, go file close window then start terminal again.
To copy deb program repackages from one directory to another.
user7@user7-356HZM-S2:~/repository$ cd ~/Programs
user7@user7-356HZM-S2:~/Programs$ ls
debian Progbacs Repackages ubuntu10
user7@user7-356HZM-S2:~/Programs$ cd ~/Programs/Repackages
List the contents of the repackages directory. Highlight the names of those packages to be copied and go edit copy them to put them on the clipboard. Open the text editor gedit. Paste the copied names into the editor. Delete the space after each name and press space bar once to separate each name so that the repackages do not execute when pasted. Highlight and copy the edited names and paste them into the next cp command in terminal.
user7@user7-356HZM-S2:~/Programs/Repackages$ cp dpkg_1.15.8.4ubuntu3.1_i386.deb dpkg_1.15.8.4ubuntu3_i386.deb dpkg-repack_1.37_all.deb dpkg-www_2.54+nmu1_all.deb ~/repository
user7@user7-356HZM-S2:~/Programs/Repackages$ ls ~/repository
1stread
apt_0.8.3ubuntu7.3_i386.deb
apt_0.8.3ubuntu7_i386.deb
aptdaemon_0.31+bzr506-0ubuntu2_all.deb
aptdaemon_0.31+bzr506-0ubuntu6.1_all.deb
aptitude_0.6.3-2ubuntu4_i386.deb
aptitude-doc-en_0.6.3-2ubuntu4_all.deb
aptoncd_0.1.98+bzr117-1_all.deb
apt-src_0.25.1-0.1_all.deb
apturl_0.4.1ubuntu7.1_i386.deb
apturl-common_0.4.1ubuntu7.1_i386.deb
apt-xapian-index_0.39ubuntu1_all.deb
dpkg_1.15.8.4ubuntu3.1_i386.deb
dpkg_1.15.8.4ubuntu3_i386.deb
dpkg-repack_1.37_all.deb
dpkg-www_2.54+nmu1_all.deb
gdebi-0-6-3-es-en-br-fr-de-it-ru-cn-ubu.deb
oe-build-essentials.deb
repository10
repository10how
user7@user7-356HZM-S2:~/Programs/Repackages$
To list show users who are logged into the computer system.
user7@user7-271GZM-S2:~$ users
user7 user7
Only one user logged in.
To show uses who are logged in.
user7@user7-271GZM-S2:~$ who
user7 tty7 2017-05-30 13:32 (:0)
user7 pts/0 2017-05-30 13:33 (:0.0)
user7@user7-271GZM-S2:~$
To show only real, local users of the system.
user7@user7-271GZM-S2:~$ cat /etc/passwd | grep 'home' | cut -d: -f1
syslog
usbmux
saned
user7
smsd
user7@user7-271GZM-S2:~$
To show the hostname of the computer and which IP address it points to:
user7@user7-271GZM-S2:~$ getent hosts
192.168.0.14 user7-271GZM-S2
127.0.0.1 localhost.localdomain localhost
127.0.0.1 user7-271GZM-S2 localhost6.localdomain6 localhost6
127.0.1.1 user7-271GZM-S2
127.0.0.1 localhost ip6-localhost ip6-loopback
user7@user7-271GZM-S2:~$
The host name is user7 and the IP is the first number.
To list all the files in a long directory and scroll the page:
user7@user7-271GZM-S2:~/Documents$ ls | less
ab16715.odt
ab25815.odt
ab29515.pdf
abeml24315.png
abeml29515.odt
...etc
Press down arrow then up arrow to scroll. At bottom end of list, type q and press enter key to return to the Terminal command prompt.
To list -l a lot of file names in lines with commas -m across a full screen:
Click the maximise square icon in top left corner of Terminal screen.
user7@user7-356HZM-S2:~/repository$ ls -m
1stread, apt_0.8.3ubuntu7.3_i386.deb, apt_0.8.3ubuntu7_i386.deb, aptdaemon_0.31+bzr506-0ubuntu2_all.deb, aptdaemon_0.31+bzr506-0ubuntu6.1_all.deb,
aptitude_0.6.3-2ubuntu4_i386.deb, aptitude-doc-en_0.6.3-2ubuntu4_all.deb, aptoncd_0.1.98+bzr117-1_all.deb, apt-src_0.25.1-0.1_all.deb,
apturl_0.4.1ubuntu7.1_i386.deb, apturl-common_0.4.1ubuntu7.1_i386.deb, apt-xapian-index_0.39ubuntu1_all.deb, dpkg_1.15.8.4ubuntu3.1_i386.deb,
... etc ... long lsit
libxt6_1.0.7-1_i386.deb, libxtst6_1.1.0-3_i386.deb, libxv1_1.0.5-1_i386.deb, libxvidcore4_1.2.2+debian-1ubuntu2_i386.deb, libxvmc1_1.0.5-1ubuntu1_i386.deb,
libxxf86dga1_1.1.1-2_i386.deb, libxxf86vm1_1.1.0-2_i386.deb, libyaml-perl_0.71-1_all.deb, libyaml-syck-perl_1.09-1_i386.deb,
libzbar0_0.10+doc-3build1_i386.deb, libzephyr4_3.0-1_i386.deb, libzrtpcpp-1.4-0_1.4.6-1_i386.deb, oe-build-essentials.deb, repository10how
user7@user7-356HZM-S2:~/repository$
To list files in columns across -x the screen.
user7@user7-356HZM-S2:~/repository$ ls -x
To find where a program is located in the system:
In this example the program looked for is ldconfig.
user7@user7-356HZM-S2:/$ whereis ldconfig
ldconfig: /sbin/ldconfig /sbin/ldconfig.real /usr/share/man/man8/ldconfig.8.gz
user7@user7-356HZM-S2:/$
To show verify and list all the shared libraries libs found by the library maintenance and control program called Ldconfig:
The command ldconfig -v should be run from root # or sudo to work properly.
user7@user7-356HZM-S2:/$ ldconfig -v
etc ... long list
libdecoration.so.0 -> libdecoration.so.0.0.0
libgobject-2.0.so.0 -> libgobject-2.0.so.0.2600.1
/usr/lib/i686: (hwcap: 0x0008000000000000)
/usr/lib/sse2: (hwcap: 0x0000000004000000)
libspeexdsp.so.1 -> libspeexdsp.so.1.5.0
libspeex.so.1 -> libspeex.so.1.5.0
/usr/lib/i686/cmov: (hwcap: 0x0008000000008000)
libavformat.so.52 -> libavformat.so.52.64.2
libavcodec.so.52 -> libavcodec.so.52.72.2
libavutil.so.50 -> libavutil.so.50.15.1
libswscale.so.0 -> libswscale.so.0.11.0
libpostproc.so.51 -> libpostproc.so.51.2.0
user7@user7-356HZM-S2:/$
To print to screen show a list of directories and libraries stored in the current cache:
Expand the Terminal window to full screen for a long list.
user7@user7-356HZM-S2:/$ ldconfig -p
long list
...etc
libGLU.so.1 (libc6) => /usr/lib/libGLU.so.1
libGL.so.1 (libc6) => /usr/lib/mesa/libGL.so.1
libFS.so.6 (libc6) => /usr/lib/libFS.so.6
libFLAC.so.8 (libc6) => /usr/lib/libFLAC.so.8
libBrokenLocale.so.1 (libc6, OS ABI: Linux 2.6.15) => /lib/libBrokenLocale.so.1
libBrokenLocale.so (libc6, OS ABI: Linux 2.6.15) => /usr/lib/libBrokenLocale.so
ld-linux.so.2 (ELF) => /lib/ld-linux.so.2
user7@user7-356HZM-S2:/$
Scroll back through the list using the top arrow of the scroll bar at right. Do not use arrow keys.
To enter and run ldconfig -l in library mode:
user7@user7-356HZM-S2:~/repository$ sudo ldconfig ~l
/sbin/ldconfig.real: relative path `~l' used to build cache
user7@user7-356HZM-S2:~/repository$
To find the ldconfig files in the /etc directory:
user7@user7-356HZM-S2:/$ cd /etc
user7@user7-356HZM-S2:/etc$ ls
scroll list
ConsoleKit ldap sane.d
console-setup ld.so.cache screenrc
couchdb ld.so.conf securetty
cron.d ld.so.conf.d security
cron.daily legal sensors3.conf
cron.hourly lftp.conf sensors.d
cron.monthly libpaper.d services
etc ...
groff passwd xulrunner-1.9.2
group passwd- zsh_command_not_found
user7@user7-356HZM-S2:/etc$
To view the file called ld.so.conf:
user7@user7-356HZM-S2:/etc$ gedit ld.so.conf
user7@user7-356HZM-S2:/etc$
Only one line is in this file:
include /etc/ld.so.conf.d/*.conf
That file generally is not edited or changed in any way.
Change to that directory referred to and list what is in it.
user7@user7-356HZM-S2:/etc$ cd /etc/ld.so.conf.d
user7@user7-356HZM-S2:/etc/ld.so.conf.d$ ls
GL.conf i686-linux-gnu.conf libasound2.conf libc.conf
user7@user7-356HZM-S2:/etc/ld.so.conf.d$
To open and write a new config file to show ldconfig the repository where more library files are stored:
user7@user7-356HZM-S2:~$ cd /etc
user7@user7-356HZM-S2:/etc$ ls l*
ld.so.cache lftp.conf login.defs lsb-release
ld.so.conf locale.alias logrotate.conf ltrace.conf
legal localtime lsb-base-logging.sh
ldap:
ldap.conf
ld.so.conf.d:
GL.conf i686-linux-gnu.conf libasound2.conf libc.conf repository.conf
user7@user7-356HZM-S2:/etc$ ls /etc/ld.so.conf.d
GL.conf i686-linux-gnu.conf libasound2.conf libc.conf repository.conf
user7@user7-356HZM-S2:/etc$ sudo gedit repository.conf
[sudo] password for user7:
That opens a new file called repository.conf. Type into the file the path to the repository.
# This is a configuration file to link ldconfig to library files in the local repository.
# ~/repository
/home/user7/repository
That last line is the path.
Save the file and exit gedit.
user7@user7-356HZM-S2:/etc$ sudo ls /etc/ld.so.conf.d/repository.conf
[sudo] password for user7:
/etc/ld.so.conf.d/repository.conf
user7@user7-356HZM-S2:/etc$
That is the new source file.
Update the sources list.
user7@user7-356HZM-S2:/etc$ sudo ldconf
user7@user7-356HZM-S2:/etc$
To update enable initialise the sources list for local repository:
The sources list must have the url address of the repository, as shown below.
user7@user7-356HZM-S2:/$ sudo apt-get update
Ign file: ./ Release.gpg
Ign file:/home/user7/repository/ ./ Translation-en
Ign file:/home/user7/repository/ ./ Translation-en_US
Ign file: ./ Release
Ign file: ./ Packages
Ign file: ./ Packages
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en_US
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/restricted Translation-en
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/restricted Translation-en_US
Reading package lists... Done
user7@user7-356HZM-S2:/$
Done means that the list is updated. Ign means that apt-get ignored some files in the repository because they were already download. So the source is listed right as
deb file:/home/user7/repository ./
To match the main sources.list with the repository sources list so apt-get can find the offline repository:
Find and open the sources.list.
In a separate terminal window, find and open the repository sources list.
user7@user7-356GZM-S2:~$ cd /etc/apt
user7@user7-356GZM-S2:/etc/apt$ ls
apt.conf.d sources.list sources.list.d trusted.gpg
preferences.d sources.list~ sources.list.save trusted.gpg~
secring.gpg sources.list.backup trustdb.gpg trusted.gpg.d
user7@user7-356GZM-S2:/etc/apt$ cd /etc/apt/sources.list.d
user7@user7-356GZM-S2:/etc/apt/sources.list.d$ ls
opera.list opera.list.save repository.list repository.list.save
user7@user7-356GZM-S2:/etc/apt/sources.list.d$ sudo gedit repository.list
[sudo] password for user7:
Edit both lists so that the right sources line is the same in both lists.
Update the list.
user7@user7-356GZM-S2:/etc/apt/sources.list.d$ sudo apt-get update
Ign file: Release.gpg
Ign file:/home/user7/repository/ Translation-en
Ign file:/home/user7/repository/ Translation-en_US
Ign file: Release
Ign file: Packages
Ign file: Packages
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007) maverick Release.gpg
Err file: Packages
Undetermined Error
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/main Translation-en_US
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/restricted Translation-en
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007)/ maverick/restricted Translation-en_US
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007) maverick/main i386 Packages/DiffIndex
Ign cdrom://Ubuntu 10.10 _Maverick Meerkat_ - Release i386 (20101007) maverick/restricted i386 Packages/DiffIndex
W: Failed to fetch file:/home/user7/repository/Packages.gz Undetermined Error
E: Some index files failed to download, they have been ignored, or old ones used instead.
user7@user7-356GZM-S2:/etc/apt/sources.list.d$
To check that Ldconfig has found and listed the local ~/repository: Expand Terminal window to full screen.
user7@user7-356HZM-S2:~$ sudo ldconfig -p
libmpeg2convert.so.0 (libc6) => /usr/lib/libmpeg2convert.so.0
libmpeg2.so.0 (libc6) => /usr/lib/libmpeg2.so.0
libmp.so.3 (libc6) => /usr/lib/libmp.so.3
libmozsqlite3.so (libc6) => /home/user7/repository/libmozsqlite3.so
libmm.so.14 (libc6) => /usr/lib/libmm.so.14
libmission-control-plugins.so.0 (libc6) => /usr/lib/libmission-control-plugins.so.0
libmikmod.so.2 (libc6) => /usr/lib/libmikmod.so.2 lib
etc ..
libFLAC.so.8 (libc6) => /usr/lib/libFLAC.so.8
libBrokenLocale.so.1 (libc6, OS ABI: Linux 2.6.15) => /lib/libBrokenLocale.so.1
libBrokenLocale.so (libc6, OS ABI: Linux 2.6.15) => /usr/lib/libBrokenLocale.so
ld-linux.so.2 (ELF) => /lib/ld-linux.so.2
user7@user7-356HZM-S2:~$
The home repository is shown in the list above.
To edit the repository config file:
user7@user7-356HZM-S2:~$ sudo gedit /etc/ld.so.conf.d/repository.conf
Gedit opens the file for editing. Save, exit.
user7@user7-356HZM-S2:~$
To remount Ubuntu setup disk so APT Synaptic can find it:
Insert the Ubuntu setup CD disk into drive.
user@user-xps:/$ cd /media ls
user@user-xps:/media$ ls
apt floppy floppy0 Ubuntu 10.10 i386
user@user-xps:/media$ umount /media/Ubuntu*
Type that asterisk so Terminal can read the ubuntu name.
user@user-xps:/media$ ls
apt floppy floppy0
The CD is unmounted.
user@user-xps:/media$ mount /dev/sr0 /media/apt
mount: only root can do that
user@user-xps:/media$ sudo mount /dev/sr0 /media/apt
[sudo] password for user:
user@user-xps:/media$ cd /media/apt
user@user-xps:/media/apt$ ls
autorun.inf dists md5sum.txt preseed usb-creator.exe
boot install pics README.diskdefines wubi.exe
casper isolinux pool ubuntu
There is the CD named ubuntu, moved from /media to /media/apt .
But apt still may not find it. So instead use command apt-cdrom add to automatically remount the disk and update the system.
To edit the sources list so Synaptic will try to open a mirror repository: -
Read Synaptic's initial error message on starting.
Type is not known on line 14.
In terminal, open sources.list and comment out line 14 or whichever line is in error.
Restart synaptic.
Run apt-get update and it will say whether it can read the lines in the list.
To check and report on the file system urgently:
Reset -c maximum count and other options of Tune2fs with this command.
user@user-xps:~$ sudo tune2fs -c 1 -i 1m /dev/sda1
[sudo] password for user:
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to 1
Setting interval between checks to 2592000 seconds
user@user-xps:~$ exit
Restart the computer for an automatic system check at bootup.
To show report results of last file system check.
user@user-xps:~$ sudo tune2fs -l /dev/sda1
[sudo] password for user:
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: 313syspart
Last mounted on: /
Filesystem UUID: 540eef81-484d-4c94-bf3c-d601d96350ec
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 19103744
Block count: 76414464
Reserved block count: 3820723
Free blocks: 74099993
Free inodes: 18958228
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 1005
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Thu May 4 19:52:14 2017
Last mount time: Sun Jun 4 21:21:19 2017
Last write time: Sun Jun 4 21:21:07 2017
Mount count: 1
Maximum mount count: 1
Last checked: Sun Jun 4 21:21:07 2017
Check interval: 2592000 (1 month)
Next check after: Tue Jul 4 21:21:07 2017
Lifetime writes: 13 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
First orphan inode: 15733680
Default directory hash: half_md4
Directory Hash Seed: db5bb558-b6dc-4ef7-8864-420827ae7d63
Journal backup: inode blocks
user@user-xps:~$
To reset the maximum mount count back to 33 boots.
user@user-xps:~$ sudo tune2fs -c 33 /dev/sda1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to 33
user@user-xps:~exit
To browse the internet, install Luakit web browser; https://luakit.github.io/
To start Luakit browser, click the globe icon on the side bar list of program icons.
To put the Luakit icon on the list of icons:
Press ctrl-alt-t and type on the terminal command line the comand:
luakit
Then right click the luakit icon and select to bookmark it as a favourite.
To browse to a website, in Terminal run this command:
luakit webaddress
To show launch options for Luakit, run this in terminal:
luakit -h
To scroll a web page, press the down and up arrow keys.
To go to the next screen page: press page-down key
To got to back a page: press page-up key.
To show a command line in the browser:
press shift and ; together
See : commandline at bottom of screen
To go to a website from the command line in luakit, type at the colon :open webaddress.com
press enter
eg :open https://searx.org
To go to the terminal command line:
ctrl-c
To open a new tab:
:tabopen webaddress
To close down a tab, press d.
To open up the last tab, press u.
To bookmark the page now showing:
press B
that is shift-b
then in bookmarks press the save button.
To open the bookmarks list:
press gb
To open it in a new tab, gB.
To search the internet for information:
Type gB, g shift-B, to open the bookmark favourites, select a search engine, like Searx.org, type keywords to search for, press enter.
To search a web page for a key word:
Click the web page, type a forward slash then a keyword, press enter.
The keword will be highlighted on the page.
To go to the Luakit home page and documentation,
type /luakit and press enter.
To close a webpage or pages and go to a blank page, press d.
The blank page is a new tab called luakit://newtab/
To toggle the browser to full screen, press the tiny square at top right.ggBgB
To close or quit the browser, on the browser's command line type :q
press enter
Then in terminal type exit and press enter.
The user's personal luakit configuration directory is at ~/.config/luakit/
Some javascript and plugins are enabled by default.
The default search engine is
default https://duckduckgo.com/?q=%s
The default home page is https://luakit.github.io/
To show the help menu:
$ luakit -h
Conkeror is a web browser, written mainly in JavaScript, which runs from the command line in Terminal. But it no longer comes as part of the Ubuntu software package. So the commands below may not work. To learn more about Conkeror, browse to http://conkeror.org/.
To install an internet web browser to run from command line:
user7@user7-356GZM-S2:~/repository$ sudo dpkg -i conkeror_0.9.2+git100804-1ubuntu1_all.deb
Selecting previously deselected package conkeror.
(Reading database ... 128369 files and directories currently installed.)
Unpacking conkeror (from conkeror_0.9.2+git100804-1ubuntu1_all.deb) ...
Setting up conkeror (0.9.2+git100804-1ubuntu1) ...
Processing triggers for man-db ...
Processing triggers for desktop-file-utils ...
Processing triggers for python-gmenu ...
Rebuilding /usr/share/applications/desktop.en_US.utf8.cache...
Processing triggers for python-support ...
user7@user7-356GZM-S2:~/repository$
Start run the browser from Terminal.
user7@user7-356GZM-S2:~/repository$ conkeror
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST: Component returned failure code: 0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) [nsILocalFile.isSymlink]
load_rc()@chrome://conkeror/content/rc.js:25
handle_command_line()@chrome://conkeror/content/command-line.js:181
anonymous()@file:///usr/share/conkeror/components/commandline.js:23
Too many errors. Try connecting computer to internet then reinstalling conkeror.
user7@user7-356GZM-S2:~$ cd ~/repository
user7@user7-356GZM-S2:~/repository$ ls conk*
conkeror_0.9.2+git100804-1ubuntu1_all.deb
user7@user7-356GZM-S2:~/repository$ sudo dpkg -i ~/repository/conkeror_0.9.2+git100804-1ubuntu1_all.deb
(Reading database ... 128592 files and directories currently installed.)
Preparing to replace conkeror 0.9.2+git100804-1ubuntu1 (using .../conkeror_0.9.2+git100804-1ubuntu1_all.deb) ...
Unpacking replacement conkeror ...
Setting up conkeror (0.9.2+git100804-1ubuntu1) ...
Processing triggers for man-db ...
Processing triggers for desktop-file-utils ...
Processing triggers for python-gmenu ...
Rebuilding /usr/share/applications/desktop.en_US.utf8.cache...
Processing triggers for python-support ...
user7@user7-356GZM-S2:~/repository$
The conkeror help manual window opens. Click it and use key combinations as instructed. Maximise the window and press g key to open a url field at bottom of page. To quit exit conkeror and return to Terminal command prompt, Ctrl-x Ctrl-c close the conkeror window. See conkeror.txt for instructions.
To browse the internet from a command line:
In Terminal, type conkeror to start the web browser. See instructions above and conkeror.txt.
To copy files for VLC media player program on to a USB stick called PHEONIXSONG then paste them into another computer running Ubuntu 10, into three directories: -
/etc/vlc
/usr/lib/vlc
/var/lib/dpkg -i /info
Searchmonkey can be used to find files before starting Terminal to copy them.
user7@user7-desktop:~$ ls /media/PHEONIXSONG/vlc
user7@user7-desktop:~$ ls /etc/vlc
http lua
user7@user7-desktop:/etc/vlc$ cp -r * /media/PHEONIXSONG/vlc
user7@user7-desktop:/etc/vlc$ ls
http luaq
user7@user7-desktop:/$ sudo mkdir /media/PHEONIXSONG/vlc/usrlib
user7@user7-desktop:/$ ls /media/PHEONIXSONG/vlc
http lua usrlib vlc
user7@user7-desktop:/$ \
user7@user7-desktop:~$ cd /usr/lib
user7@user7-desktop:/usr/lib$ cp -r /vlc /media/PHEONIXSONG/vlc
cp: cannot stat `/vlc': No such file or directory
user7@user7-desktop:/usr/lib$ cp -r /usr/lib/vlc /media/PHEONIXSONG/vlcuser7@user7-desktop:/usr/lib$
user7@user7-desktop:/usr/lib$ ls /usr/lib/vlc
lua plugins vlc-cache-gen
user7@user7-desktop:/usr/lib$
user7@user7-desktop:~$ sudo mkdir /media/PHEONIXSONG/vlc/info
user7@user7-desktop:~$ ls /media/PHEONIXSONG/vlc
http info lua plugins usrlib vlc vlc-cache-gen
user7@user7-desktop:~$ cd /var/lib/dpkg/info
(list of files in /info direcotry)
zlib1g.md5sums
zlib1g.postinst
zlib1g.postrm
zlib1g.shlibs
zlib1g.symbols
user7@user7-desktop:/var/lib/dpkg/info$ cp libvlc*.* /media/PHEONIXSONG/vlc/infouser7@user7-desktop:/var/lib/dpkg/info$ cp vlc*.* /media/PHEONIXSONG/vlc/info
user7@user7-desktop:/var/lib/dpkg/info$ ls /media/PHEONIXSONG/vlc/info
libvlc5.list libvlccore4.md5sums vlc-data.md5sums vlc-nox.triggers
libvlc5.md5sums libvlccore4.postinst vlc.list vlc-plugin-notify.list
libvlc5.postinst libvlccore4.postrm vlc.md5sums vlc-plugin-notify.md5sums
libvlc5.postrm libvlccore4.shlibs vlc-nox.list vlc-plugin-pulse.list
libvlc5.shlibs libvlccore4.symbols vlc-nox.md5sums vlc-plugin-pulse.md5sums
libvlc5.symbols vlc-data.conffiles vlc-nox.postinst vlc.postinst
libvlccore4.list vlc-data.list vlc-nox.prerm vlc.postrm
user7@user7-desktop:/var/lib/dpkg/info$
user7@user7-desktop:/usr/lib$ sudo cp -r libavcodec.so.52 /media/PHEONIXSONG/codecs/usr/lib
cp: cannot create symbolic link `/media/PHEONIXSONG/codecs/usr/lib/libavcodec.so.52': Operation not permitted
user7@user7-desktop:/usr/lib$ sudo cp libavcodec.so.52 /media/PHEONIXSONG/codecs/usr/lib
user7@user7-desktop:/usr/lib$
user7@user7-desktop:/usr/lib/qt4/plugins/codecs$ /usr/lib/i686/cmov
bash: /usr/lib/i686/cmov: is a directory
user7@user7-desktop:/usr/lib/qt4/plugins/codecs$ ls
libqcncodecs.so libqjpcodecs.so libqkrcodecs.so libqtwcodecs.so
user7@user7-desktop:/usr/lib/qt4/plugins/codecs$ sudo cp -r *.* /media/PHEONIXSONG/codecs/usr/lib/i686/cmov
user7@user7-desktop:/usr/lib/qt4/plugins/codecs$
user7@user7-desktop:/usr/share/doc$ cd /usr/share/doc/libavcodec52
user7@user7-desktop:/usr/share/doc/libavcodec52$ ls
changelog.Debian.gz changelog.gz codecs.txt.gz copyright CREDITS MAINTAINERS.gz README.Debian.gz TODO
user7@user7-desktop:/usr/share/doc/libavcodec52$ sudo cp -r *.* /media/PHEONIXSONG/codecs/usr/share/doc/libavcodec52
user7@user7-desktop:/usr/share/doc/libavcodec52$
libgdata7.md5sums libwildmidi0.postrm zlib1g.shlibs
libgdata7.postinst libwildmidi0.shlibs zlib1g.symbols
libgdata7.postrm libwildmidi0.symbols
user7@user7-desktop:/var/lib/dpkg/info$ cp -r gnome-codec-install*.* libavcodec52*.* /media/PHEONIXSONG/codecs//var/lib/dpkg/info
user7@user7-desktop:/var/lib/dpkg/info$
Dpkg-scanpackages program is not installed by default with Ubuntu but can be installed from the install cd disk.
To list packages installed on the system:
user7@user7-356HZM-S2:/$ dpkg -l
long list ... etc ...
ii zenity 2.32.0-0ubuntu Display graphical dialog boxes from shell sc
ii zip 3.0-3 Archiver for .zip files
ii zlib1g 1:1.2.3.4.dfsg compression library - runtime
user7@user7-356HZM-S2:/$
To see whether a program is installed. This command includes a pipe, the vertical line on key at far right of keyboard.
user7@user7-356HZM-S2:/$
user7@user7-356HZM-S2:/$ dpkg -l | grep apache2
user7@user7-356HZM-S2:/$ dpkg -l | grep Mines
ii gnomie 1:2.32.0-0ubuntu1 Minesweeper logic puzzle game
user7@user7-356HZM-S2:/$
That shows apache2 is not installed and Mines game is.
To install a program from the repository:
Change to the repository directory. The command is dpkg -i. The rest is the name of the deb program package.
user7@user7-356HZM-S2:~/repository$ dpkg -i dpkg-repack_1.37_all.deb
dpkg: requested operation requires superuser privilege
user7@user7-356HZM-S2:~/repository$ sudo dpkg -i dpkg-repack_1.37_all.deb
[sudo] password for user7:
Selecting previously deselected package dpkg-repack.
(Reading database ... 127428 files and directories currently installed.)
Unpacking dpkg-repack (from dpkg-repack_1.37_all.deb) ...
Setting up dpkg-repack (1.37) ...
Processing triggers for man-db ...
user7@user7-356HZM-S2:~/repository$
Use dpkg to install a deb package but not to uninstall it as dpkg cannot uninstall all dependencies properly and will leave library files not working properly.
To comment out a line of text in a program script so that it cannot be executed yet can be read by a programmer, for Perl, Python, PHP and Ruby scripts, type a hash # at the beginning of the line.
# This is a comment, not a command.
To show which programs reverse depend on a package which is in the cache and which packages that package depends upon. In this example it is a library package.
user7@user7-356HZM-S2:/$ sudo apt-cache showpkg libspeechd2
Package: libspeechd2
Versions:
0.7-5ubuntu3 (/var/lib/dpkg/status)
Description Language:
File: /var/lib/dpkg/status
MD5: 923e5a99c6ce5f37dbf40590d502b3b3
Reverse Depends:
speech-dispatcher,libspeechd2
Dependencies:
0.7-5ubuntu3 - libc6 (2 2.4) libglib2.0-0 (2 2.12.0) libspeechd0 (2 0.3)
Provides:
0.7-5ubuntu3 -
Reverse Provides:
user7@user7-356HZM-S2:/$
Other commands of Apt-cache show long single-column lists even if piped less, too long to read unless the command includes a regex, regular expression. The regex can be the first five or six letters of a lib package name, without a wildcard.
user7@user7-356HZM-S2:~$ sudo apt-cache search libga
libgamin0 - Client library for the gamin file and directory monitoring system
libgail18 - GNOME Accessibility Implementation Library -- shared libraries
libgadu3 - Gadu-Gadu protocol library - runtime files
libgail-common - GNOME Accessibility Implementation Library -- common modules
libgail-gnome-module - GNOME Accessibility Implementation Module for GnomeUI/BonoboUI
user7@user7-356HZM-S2:~$
To command a program like apt to find a package in the current directory, indicate the current directory with ./ before the file name.
To edit the fstab file to agree with apt-cdrom.
user7@user7-356HZM-S2:~$ sudo apt-cdrom -d /cdrom
[sudo] password for user7:
apt 0.8.3ubuntu7.3 for i386 compiled on Nov 22 2011 20:51:02
Usage: apt-cdrom [options] command
apt-cdrom is a tool to add CDROM's to APT's source list. The
CDROM mount point and device information is taken from apt.conf
and /etc/fstab.
... etc ..
user7@user7-356HZM-S2:~$ cd /etc/fstab
bash: cd: /etc/fstab: Not a directory
user7@user7-356HZM-S2:~$ cd /etc
user7@user7-356HZM-S2:/etc$ ls
acpi ... etc
fonts mtab.fuselock update-notifier
foomatic mtools.conf UPower
fstab nanorc usb_modeswitch.conf
fuse.conf netscsid.conf usb_modeswitch.d
gai.conf network vim
gamin NetworkManager w3m
gconf networks wgetrc
gdb nsswitch.conf
user7@user7-356HZM-S2:/etc$ sudo gedit fstab
UUID=34294ce5-c220-4110-863b-7a32ee2862d8 /home ext2 defaults 0 2
/dev/sda1 none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
# User added this mount point for the cdrom so that apt-get could find it where it expects.
/dev/sr0 /cdrom
Save fstab and exit gedit.
user7@user7-356HZM-S2:/etc$
Fstab lists physical devices like hard drives and cdroms, not the home repository, which is a directory.
To edit the fstab configuration file so that Linux can use floppy disks:
user@user-ID:/media$ ls
floppy floppy0 user
user@user-ID:/media$ cd /etc/
user@user-ID:/etc$ ls fstab
fstab
user@user-ID:/etc$ sudo nano fstab
[sudo] password for user:
# This was the default line for fd
# /dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
# This fd line was edited by userroot
/dev/fd0 /media/floppy auto rw,noauto,user,exec,sync 0 0
If you can't access your Windows partition from Linux, aren't able to mount your CD or write to your floppy as a normal user, or have problems with your CD-RW, you probably have a misconfigured /etc/fstab file. So, you can usually fix your mounting problems by editing your fstab file.
Here is an example of how it could be edited:
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0 .
The first column is the device name. The second column is the default mount point for the device. The third column is the file system type, which could be auto, ext2, swap, vfat or whatever. The fourth column is the mount options, which could be default. The fifth is the dump options and the sixth is the file system check options, numbered 0,1 or 2.
Make sure the mount point is a directory that already exists on your system. If the mount point directory does not exist, make it with the mkdir command. To be able to write to Windows partitions from Linux, format them as Vfat, that is FAT32. Vfat is the most reliable cross-platform file system type for floppy drives. Noauto means that the drive will not be automatically mounted when the computer starts. Nouser means that only root can mount the device. RW means the device can be read and written to. Ro means read only. Exec allows a binary file to be executed on the drive, such as DOS on a floppy. Sync is the option for a floppy drive because it means that files are copied to it as soon as you run the cp command, not later. Defaults uses the default options that are rw, suid, dev, exec, auto, nouser, and async. Dump is a backup utility and fsck is a file system check utility. A zero means that the utility will not be used on the device.
Here are two more examples of lines in the fstab file.
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0
The exec option allows a program to be executed from the CD compact disk. Here the zero means it cannot be executed.
To show what is inside a package:
apt-utils_0 (copy).8.3ubuntu7.3_i386.deb
apt-xapian-index_0.39ubuntu1_allb.deb
apt-xapian-index_0.39ubuntu1_all.deb
user7@user7-356HZM-S2:~/repository$ dpkg --contents apt-utils_0.8.3ubuntu7.3_i386.deb
drwxr-xr-x root/root 0 2015-09-27 11:38 ./
drwxr-xr-x root/root 0 2015-09-27 11:38 ./usr/
drwxr-xr-x root/root 0 2015-09-27 11:38 ./usr/share/
drwxr-xr-x root/root 0 2015-09-27 11:38 ./usr/share/man/
drwxr-xr-x root/root 0 2015-09-27 11:38 ./usr/share/man/pt/
drwxr-xr-x root/root 0 2015-09-27 11:38 ./usr/share/man/pt/man1/
-rw-r--r-- root/root 1869 2011-11-23 07:55 ./usr/share/man/pt/man1/apt-extracttemplates.1.gz
-rw-r--r-- root/root 1768 2011-11-23 07:55 ./usr/share/man/pt/man1/apt-sortpkgs.1.gz
-rw-r--r-- root/root 6853 2011-11-23 07:55 ./usr/share/man/pt/man1/apt-ftparchive.1.gz
drwx ... etc ..
-rw-r--r-- root/root 1117 2011-04-21 23:36 ./usr/share/doc/apt-utils/NEWS.Debian.gz
drwxr-xr-x root/root 0 2015-09-27 11:38 ./usr/bin/
-rwxr-xr-x root/root 174348 2011-11-23 07:55 ./usr/bin/apt-ftparchive
-rwxr-xr-x root/root 26220 2011-11-23 07:55 ./usr/bin/apt-sortpkgs
-rwxr-xr-x root/root 22216 2011-11-23 07:55 ./usr/bin/apt-extracttemplates
drwxr-xr-x root/root 0 2015-09-27 11:38 ./usr/lib/
-rw-r--r-- root/root 75588 2011-11-23 07:55 ./usr/lib/libapt-inst.so.1.2.0
lrwxrwxrwx root/root 0 2012-02-21 08:15 ./usr/lib/libapt-inst.so.1.2 -> libapt-inst.so.1.2.0
user7@user7-356HZM-S2:~/repository$
To try to find and download missing deb package dependency, open a web browser and go to:
ftp://ftp.au.debian.org/ubuntu/ubuntu/ubuntu/ubuntu/ubuntu/ubuantu/pool/
Few if any of the programs or libraries there are likely to suit Ubuntu 10.
To remove orphaned dependencies.
user7@user7-356HZM-S2:~$ sudo apt-get autoremove
[sudo] password for user7:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
lilypond-data
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 6,910kB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 127790 files and directories currently installed.)
Removing lilypond-data ...
/var/lib/dpkg/info/lilypond-data.postrm: 20: kpsewhich: not found
dpkg: error processing lilypond-data (--remove):
subprocess installed post-removal script returned error exit status 127
No apport report written because MaxReports is reachedalready Errors were encountered while processing:
lilypond-data
E: Sub-process /usr/bin/dpkg returned an error code (1)
user7@user7-356HZM-S2:~$
To upgrade the operating system:
user@host-id:~$ sudo apt-get upgrade
Watch output and when prompted, type y for yes.
user@host-id:~$ sudo apt-get upgrade
[sudo] password for tom7:
Reading package lists... Done
Building dependency tree... Done etc
After this operation, 16.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd6 etc
Processing triggers for libc-bin (2.35-0ubuntu3.5) ...
Processing triggers for man-db (2.10.2-1) ...
user@host-id:~$
To login to Ubuntu free software:
user@host-id:~$ sudo login
tom7-ID login: keith
Password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-39-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
Expanded Security Maintenance for Applications is not enabled.
2 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
20 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. etc
To show list software updates to be installed:
keith@tom7-ID:~$ apt list --upgradable
Listing... Done
fonts-noto-color-emoji/jammy-updates,jammy-updates 2.042-0ubuntu0.22.04.1 all [upgradable from: 2.038-0ubuntu1]
gjs/jammy-updates 1.72.4-0ubuntu0.22.04.1 amd64 [upgradable from: 1.72.2-0ubuntu1]
libgjs0g/jammy-updates 1.72.4-0ubuntu0.22.04.1 amd64 [upgradable from: 1.72.2-0ubuntu1]
python3-update-manager/jammy-updates,jammy-updates 1:22.04.17 all [upgradable from: 1:22.04.10]
systemd-hwe-hwdb/jammy-updates,jammy-updates 249.11.4 all [upgradable from: 249.11.3]
ubuntu-advantage-tools/jammy-updates 30~22.04 amd64 [upgradable from: 29.4~22.04]
update-manager-core/jammy-updates,jammy-updates 1:22.04.17 all [upgradable from: 1:22.04.10]
keith@tom7-ID:~$
Do not try to upgrade a system like Ubuntu 10 which is no longer supported. The command sudo apt-get upgrade upgrades programs on the computer by downloading newer versions of packages.
To upgrade a program to a newer version from a package on the hard drive, the program here being called apt:
user7@user7-356HZM-S2:~/repository$ sudo dpkg -i apt_0.8.3ubuntu7.3_i386.deb
(Reading database ... 128359 files and directories currently installed.)
Preparing to replace apt 0.8.3ubuntu7 (using apt_0.8.3ubuntu7.3_i386.deb) ...
Unpacking replacement apt ...
Setting up apt (0.8.3ubuntu7.3) ...
gpg: key 437D05B5: "Ubuntu Archive Automatic Signing Key " not changed
gpg: key FBB75451: "Ubuntu CD Image Automatic Signing Key " not changed
gpg: Total number processed: 2
gpg: unchanged: 2
Processing triggers for man-db ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
user7@user7-356HZM-S2:~/repository$
Update the sources list with apt-get.
To downgrade a program to an earlier version, just install the earlier package.
To rebuild the shared library cash and map the names in that cache so programs can find libraries:
user7@user7-356HZM-S2:~$ sudo ldconfig
user7@user7-356HZM-S2:~$
To check whether ldconfig has created its temporary cache file called ld.so.cache in the root directory called /etc.
user7@user7-356HZM-S2:~$ cd /etc
user7@user7-356HZM-S2:/etc$ ls ld*
ld.so.cache ld.so.conf
ldap:
ldap.conf
ld.so.conf.d:
GL.conf i686-linux-gnu.conf libasound2.conf libc.conf repository.conf
user7@user7-356HZM-S2:/etc$
user7@user7-356HZM-S2:/etc$ gedit ld.so.cache
user7@user7-356HZM-S2:/etc$
Do not open or edit that file.
To change the ownership of a file:
In this example the owner's name is user7 and the file is called 2Btested.
user7@user7-356HZM-S2:~$ cd ~/Desktop
user7@user7-356HZM-S2:~/Desktop$ sudo chown user7 2Btested
To change recursively the ownership of a group of files in a directory:
user7@user7-356HZM-S2:~/Desktop$ cd /
user7@user7-356HZM-S2:/$ sudo chown -R user7 ~/Desktop/debfonts
user7@user7-356HZM-S2:/$
To change the group ownership of files or directories:
chgrp --help
To change the permissions of files or directories.
chmod --help
To install recursively all the packages from a directory.
root# dpkg -R --install /directoryname
or directoryname/
To open an account for another user:
useradd options username
peter@peter-H89U-ED4:~$ sudo useradd george
[sudo] password for peter:
peter@peter-H89U-ED4:~$
This command sets up a user account for George with the usual defaults as no options have been typed.
To unlock a new user account, use the password passwd command.
peter@peter-H89U-ED4:~$ sudo passwd george
[sudo] password for superuser:
Then you add a password for the new user.
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
peter@peter-H89U-ED4:~$
User login passwords information is stored in two files: /etc/passwd and /etc/shadow. The root user account is the only system account which has a password. Other system accounts are marked with an x to show they are locked. Passwords are stored encrypted in /etc/shadow. This file lists user account names, passwords and password expiry dates but not user ID numbers. An asterisk * or exclamation mark ! means that the account does not have a password and is locked because it is used by the system.
To show password information:
user@user-H64C-ED4:~$ sudo cat /etc/shadow | more
root:!:1794:0:9966799:7:::
daemon:*:13212:0:96659:7:::
bin:*:17212:0:2299:7:::
sys:*:17212:0:2299 ... etc
username:$6$rZtiwiln$TLvxdWOr7FFXRwQpI/aU
1V0cpJ0FZxdn0qh7N9XFBvwCiiNetbJik0bQ9R
BKHbIisYk/UPqATwghB1i7884:0:99999:7:::
debian-tor:*:17976:999:7:::
george:$6$lln3CRV$rVeB1/zjel.rX0JvdcTZ
9AfhIsZiXlEfCqmJ3xveeQuM2MTXGcPsqKJCgZr
46UfZk/0pPTFIc/52kPU1:18067:0:22999:7:::
user@user-H64C-ED4:~$
Users are the ones without an * asterisk.
Summary of Linux commands
Most commands work with all Linux operating systems but some only work with some systems. If a command does not seem to work, carefully check the syntax wording of the command. Terminal says if the program a command refers to is not installed.
Name Category Description First appeared
admin SCCS Create and administer SCCS files PWB UNIX
alias Misc Define or display aliases
ar Misc Create and maintain library archives Version 1 AT&T UNIX
asa Text processing Interpret carriage-control characters System V
at Process management Execute commands at a later time Version 7 AT&T UNIX
awk Text processing Pattern scanning and processing language Version 7 AT&T UNIX
basename Filesystem Return non-directory portion of a pathname; see also dirname Version 7 AT&T UNIX
batch Process management Schedule commands to be executed in a batch queue
bc Misc Arbitrary-precision arithmetic language Version 6 AT&T UNIX
bg Process management Run jobs in the background
cc/c99 C programming Compile standard C programs IEEE Std 1003.1-2001
cal Misc Print a calendar Version 5 AT&T UNIX
cat Filesystem Concatenate and print files Version 1 AT&T UNIX
cd Filesystem Change the working directory Version 6 AT&T UNIX
cflow C programming Generate a C-language call graph System V
chgrp Filesystem Change the file group ownership PWB UNIX
chmod Filesystem Change the file modes/attributes/permissions Version 1 AT&T UNIX
chown Filesystem Change the file ownership Version 1 AT&T UNIX
cksum Filesystem Write file checksums and sizes 4.4BSD
cmp Filesystem Compare two files; see also diff Version 1 AT&T UNIX
comm Text processing Select or reject lines common to two files Version 4 AT&T UNIX
command Shell programming Execute a simple command
compress Filesystem Compress data 4.3BSD
cp Filesystem Copy files Version 1 AT&T UNIX
crontab Misc Schedule periodic background work System V
csplit Text processing Split files based on context PWB UNIX
ctags C programming Create a tags file 3BSD
cut Text processing Cut out selected fields of each line of a file System III
cxref C programming Generate a C-language program cross-reference table System V
date Misc Display the date and time Version 1 AT&T UNIX
dd Filesystem Convert and copy a file Version 5 AT&T UNIX
delta SCCS Make a delta (change) to an SCCS file PWB UNIX
df Filesystem Report free disk space Version 1 AT&T UNIX
diff Text processing Compare two files; see also cmp Version 5 AT&T UNIX
dirname Filesystem Return the directory portion of a pathname; see also basename System III
du Filesystem Estimate file space usage Version 1 AT&T UNIX
echo Shell programming Write arguments to standard output Version 2 AT&T UNIX
ed Text processing The standard text editor Version 1 AT&T UNIX
env Misc Set the environment for command invocation System III
ex Text processing Text editor 1BSD
expand Text processing Convert tabs to spaces 3BSD
expr Shell programming Evaluate arguments as an expression Version 7 AT&T UNIX
false Shell programming Return false value Version 7 AT&T UNIX
fc Misc Process the command history list
fg Process management Run jobs in the foreground
file Filesystem Determine file type Version 4 AT&T UNIX
find Filesystem Find files Version 1 AT&T UNIX
fold Text processing Filter for folding lines 1BSD
fort77 FORTRAN77 programming FORTRAN compiler XPG4
fuser Process management List process IDs of all processes that have one or more files open System V
gencat Misc Generate a formatted message catalog
get SCCS Get a version of an SCCS file PWB UNIX
getconf Misc Get configuration values
getopts Shell programming Parse utility options
grep Misc Search text for a pattern Version 4 AT&T UNIX
hash Misc hash database access method
head Text processing Copy the first part of files PWB UNIX[citation needed]
iconv Text processing Codeset conversion HP-UX
id Misc Return user identity System V
ipcrm Misc Remove a message queue, semaphore set, or shared memory segment identifier System V
ipcs Misc Report interprocess communication facilities status System V
jobs Process management Display status of jobs in the current session
join Text processing Merges two sorted text files based on the presence of a common field Version 7 AT&T UNIX
kill Process management Terminate or signal processes Version 4 AT&T UNIX
lex C programming Generate programs for lexical tasks Version 7 AT&T UNIX
link Filesystem Create a hard link to a file Version 1 AT&T UNIX
ln Filesystem Link files Version 1 AT&T UNIX
locale Misc Get locale-specific information
localedef Misc Define locale environment
logger Shell programming Log messages 4.3BSD
logname Misc Return the user's login name 4.4BSD
lp Text processing Send files to a printer System V
ls Filesystem List directory contents Version 1 AT&T UNIX
m4 Misc Macro processor PWB UNIX
mailx Misc Process messages Version 1 AT&T UNIX
make Programming Maintain, update, and regenerate groups of programs PWB UNIX
man Misc Display system documentation Version 2 AT&T UNIX
mesg Misc Permit or deny messages Version 1 AT&T UNIX
mkdir Filesystem Make directories Version 1 AT&T UNIX
mkfifo Filesystem Make FIFO special files 4.4BSD[dubious – discuss]
more Text processing Display files on a page-by-page basis 3BSD
mv Filesystem Move or rename files Version 1 AT&T UNIX
newgrp Misc Change to a new group (functionaliy similar to sg[1]) Version 6 AT&T UNIX
nice Process management Invoke a utility with an altered nice value Version 4 AT&T UNIX
nl Text processing Line numbering filter System III
nm C programming Write the name list of an object file Version 1 AT&T UNIX
nohup Process management Invoke a utility immune to hangups Version 4 AT&T UNIX
od Misc Dump files in various formats Version 1 AT&T UNIX
paste Text processing Merge corresponding or subsequent lines of files Version 32V AT&T UNIX
patch Text processing Apply changes to files 4.3BSD
pathchk Filesystem Check pathnames
pax Misc Portable archive interchange 4.4BSD[citation needed]
pr Text processing Print files Version 1 AT&T UNIX
printf Shell programming Write formatted output 4.3BSD-Reno
prs SCCS Print an SCCS file PWB UNIX
ps Process management Report process status Version 4 AT&T UNIX
pwd Filesystem print working directory - Return working directory name Version 5 AT&T UNIX
qalter Batch utilities Alter batch job
qdel Batch utilities Delete batch jobs
qhold Batch utilities Hold batch jobs
qmove Batch utilities Move batch jobs
qmsg Batch utilities Send message to batch jobs
qrerun Batch utilities Rerun batch jobs
qrls Batch utilities Release batch jobs
qselect Batch utilities Select batch jobs
qsig Batch utilities Signal batch jobs
qstat Batch utilities Show status of batch jobs
qsub Batch utilities Submit a script
read Shell programming Read a line from standard input
renice Process management Set nice values of running processes 4BSD
rm Filesystem Remove directory entries Version 1 AT&T UNIX
rmdel SCCS Remove a delta from an SCCS file PWB UNIX
rmdir Filesystem Remove directories, if they are empty. Version 1 AT&T UNIX
sact SCCS Print current SCCS file-editing activity System III
sccs SCCS Front end for the SCCS subsystem 4.3BSD
sed Text processing Stream editor Version 7 AT&T UNIX
sh Shell programming Shell, the standard command language interpreter Version 7 AT&T UNIX (in earlier versions, sh was either the Thompson shell or the PWB shell)
sleep Shell programming Suspend execution for an interval Version 4 AT&T UNIX
sort Text processing Sort, merge, or sequence check text files Version 1 AT&T UNIX
split Misc Split files into pieces Version 3 AT&T UNIX
strings C programming Find printable strings in files 2BSD
strip C programming Remove unnecessary information from executable files Version 1 AT&T UNIX
stty Misc Set the options for a terminal Version 2 AT&T UNIX
tabs Misc Set terminal tabs PWB UNIX
tail Text processing Copy the last part of a file PWB UNIX[citation needed]
talk Misc Talk to another user 4.2BSD
tee Shell programming Duplicate the standard output Version 5 AT&T UNIX
test Shell programming Evaluate expression Version 7 AT&T UNIX
time Process management Time a simple command Version 3 AT&T UNIX
touch Filesystem Change file access and modification times Version 7 AT&T UNIX
tput Misc Change terminal characteristics System V
tr Text processing Translate characters Version 4 AT&T UNIX
true Shell programming Return true value Version 7 AT&T UNIX
tsort Text processing Topological sort Version 7 AT&T UNIX
tty Misc Return user's terminal name Version 1 AT&T UNIX
type Misc Displays how a name would be interpreted if used as a command
ulimit Misc Set or report file size limit
umask Misc Get or set the file mode creation mask System III
unalias Misc Remove alias definitions
uname Misc Return system name PWB UNIX
uncompress Misc Expand compressed data 4.3BSD
unexpand Text processing Convert spaces to tabs 3BSD
unget SCCS Undo a previous get of an SCCS file System III
uniq Text processing Report or filter out repeated lines in a file Version 3 AT&T UNIX
unlink Filesystem Call the unlink function Version 1 AT&T UNIX
uucp Network System-to-system copy Version 7 AT&T UNIX
uudecode Network Decode a binary file 4BSD
uuencode Network Encode a binary file 4BSD
uustat Network uucp status inquiry and job control System III
uux Process management Remote command execution Version 7 AT&T UNIX
val SCCS Validate SCCS files System III
vi Text processing Screen-oriented (visual) display editor 1BSD
wait Process management Await process completion Version 4 AT&T UNIX
wc Text processing Line, word and byte or character count Version 1 AT&T UNIX
what SCCS Identify SCCS files PWB UNIX
who System administration Display who is on the system Version 1 AT&T UNIX
write Misc Write to another user's terminal Version 1 AT&T UNIX
xargs Shell programming Construct argument lists and invoke utility PWB UNIX
yacc C programming Yet another compiler compiler PWB UNIX
zcat Text processing Expand and concatenate data 4.3BSD
Commands and syntax
apt-get: Search for and install software packages (Debian/Ubuntu)
cal: Display a calendar
cat: Display the contents of a file, cat filename.extension
example wae@tomt-S2L:~/Documents$ cat vistause.txt
cd = change directory, eg to go back to the home directory type cd ~, or go to root directory cd / , or go to desktop user@user-numb5GCM-S2L:/$ cd ~/Desktop
eg2 change from root directory to desktop wae@tomt-S2L:/$ cd ~/Desktop
cp = copy a file, see also "open"
cmp: Compare two files
chattr: set security attributes for a file and block even root access to a file. Generally do not use this command.
ctrl+R = search for a previous command, hold ctrl key and press the R key then type the command to look for
cfdisk: Partition table manipulator for Linux
clear: Clear terminal screen
cmp: Compare two files, eg yne@yne-356HCM-S2L:~/Desktop$ cmp sudohow test
df = display filesystem disk space on mounted partitions
df -h = show disk space in megabits or gigabits
du = display how much disk space is being used
du -s = display summary of disk usage
du -h display disk usage simply
date: Display or change the date & time
diff: Display the differences between two files
eg the first file is called email, the second is called addresses
diff email addresses
2a3,4
> Jean JRS@pollux.ucs.co
> Jim jim@frolix8
This displays a line by line difference between the file email and addresses. To make these files match you need to add (a) lines 3 and 4 (3,4) of the file addresses (>) after line 2 in the file email.
dig: DNS lookup, domain name server information, type dig www.webaddress.com
eg wae@tomt-S2L:~$ dig www.webname.com
; <<>> DiG 9.7.1-P2 <<>> www.webname.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43777
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;www.website.com. IN A
;; ANSWER SECTION:
www.website.com. 3600 IN A 66.96.160.149
;; AUTHORITY SECTION:
website.com. 172799 IN NS ns2.nethost.com. more info etc
dir: Briefly list directory contents
dirs: Display list of remembered directories
dmesg: Print kernel & driver messages
enter key = runs or executes a command
eject: Eject removable media
echo: Display message on screen when scripting. eg
~$ echo whatever I type
whatever I type
exit = exit Terminal and close it
fgrep: Search file(s) to find lines that match a fixed string
find: Search for files that meet a desired criteria
finger: This command is not found with Ubuntu unless you install the finger program.
file: Determine file type
fdformat: Low-level format a floppy disk
format: Format disks or tapes
fdisk: Partition table manipulator for Linux
free: Display memory usage
fsck: File system consistency check and repair
ftp: File Transfer Protocol, open ftp command prompt, type exit to quit ftp
function: Define Function Macros
fuser: Identify/kill the process that is accessing a file
gawk: Find and Replace text within file(s)
groups: Print group names a user is in
eg mike@mike-356HCM-S2L:~$ groups
mike adm dialout cdrom plugdev lpadmin admin sambashare
history = show previous commands
head: Output the first part of file(s)
help: Display help for a built-in command
hostname: Print or set system name
eg :~$ hostname
mike-356HCM-S2L
id = show info about user
install: Copy files and set attributes
info info = information, then press q to return to command prompt
isb_release -a = shows which Linux distribution is being used
kill: Stop a process from running
killall: Kill processes by name
ls = list files in the open directory
less: Display output one screen at a time
locate: Find files, locate filename, eg locate mlocate, see files in mlocate subdirectory,
$ locate mlocate
/etc/cron.daily/mlocate
/usr/bin/mlocate
/usr/bin/updatedb.mlocate
/usr/share/doc/mlocate
/usr/share/doc/mlocate/AUTHORS
/usr/share/doc/mlocate/NEWS.gz
logname: Print current login name
logout: Exit a login shell
look: Display lines beginning with a given string
lpc: Line printer control program
lpr: Off line print
lprint: Print a file
lprintd: Abort a print job
lsof: List open files
lsattr -a The list attributes command seems of little use with the version in Ubuntu 10.
more: Display output one screen at a time
mkdir = make a directory
mv = move or rename a file
man = user help manual
man intro = about commands
make: Recompile a group of programs
netstat: Networking information
nslookup: Query Internet name servers interactively
open: Open a file in its default application, see also cp for copy
op: Operator access, allow another user to run some sudo commands.
pwd = show which directory is open, print working directory
pr: Prepare files for printing
printcap: Printer capability database onto screen
printenv: Print environment variables info to screen
printf: Format and print data
ps: display process status
pushd: Save and then change the current directory
passwd: Change a user password
eg $ passwd
Changing password for username.
(current) UNIX password: type current password and press enter
paste: Merge lines of files
ping: Test a network connection
pkill: Stop processes from running
quota: Display disk usage and limits
rcp: Copy files between two machines
$ rcp
usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 ... [[user@]host2:]file2
reboot: Reboot the system
rename: Rename files
rm = remove or delete a file
rmdir = remove or delete an empty directory, eg ~\Documents$ rmdir directoryname
rmdir -r or rm-r = remove directory and all the files and subdirectories in it.
-r = recursively, a directory and all its files
return: Exit a shell function
sftp: Secure File Transfer Program
$ sftp
usage: sftp [-1246Cpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
[-D sftp_server_path] [-F ssh_config] [-i identity_file]
[-o ssh_option] [-P port] [-R num_requests] [-S program]
[-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host
shopt: List shell options
shutdown: Shutdown or restart linux
ssh: Secure Shell client remote login program
$ ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
screen: Multiplex terminal, run remote shells via ssh
scp: Secure copy (remote file copy)
su = sudo, root, administrator
sudo = administrator, root, su, execute a command as another user
suspend: Suspend execution of this shell
tab key = suggests a command
top = start monitoring system RAM, CPU and swap usage, press q for quit to stop monitoring
test: Evaluate a conditional expression
time: Measure Program running time
times: User and system times
traceroute: Trace route to host
eg $ traceroute
The program 'traceroute' is currently not installed. You can install it by typing:
sudo apt-get install traceroute
type: Describe a command, type anycommand
eg $ type time
time is a shell keyword
umount: Unmount a device
unalias: Remove an alias
uname -a = show all information about the system
: Create new user account
usermod: Modify user account
users: List users currently logged in
eg $ users
username username username username
v: Verbosely list directory contents (`ls -l -b')
vdir: Verbosely list directory contents (`ls -l -b')
vi: Text Editor
type :help iccf for information
~ type :q to exit
~ type :help or for on-line help
~ type :help version7 for version info
~ Running in Vi compatible mode
~ type :set nocp for Vim defaults
~ type :help cp-default for info on this
if close terminal to exit
vmstat: Report virtual memory statistics
eg $ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 955628 130916 246476 0 0 32 3 64 188 1 0 98 0
whoami = check name of user, print the current user id and name (`id -un')
which bash = find the path to bash for scripts, search the user's $path for a program file
~$ which bash
/bin/bash
wc: Print byte, word, and line counts
whereis: Search the user's $path, man pages and source files for a program
while: Execute commands
who: Print all usernames currently logged in
Wget: Retrieve web pages or files via HTTP, HTTPS or FTP
write: Send a message to another user
xdg-open: Open a file or URL in the user's preferred application.
~ = home directory, tilde
/ = root directory
.. = next directory
- = previous directory
### = start of a comment or remark which is not a command
up and down arrow keys scroll through commands
[ctrl][shift][v] - paste
[ctrl][c] - stops process
More commands
(Drag this window wider to tabulate commands for easy reading.)
sudo_root(8) sudo_root(8)
NAME
sudo_root - How to run administrative commands
SYNOPSIS
sudo command
sudo -i
By default, the password for the user "root" (the system administrator) is locked. This means you cannot login as root or use su. Instead, the installer will set up sudo to allow the user that is created during install to run all administrative commands.
This means that in the terminal you can use sudo for commands that require root privileges. All programs in the menu will use a graphical sudo to prompt for a password. When sudo asks for a password, it needs your password, this means that a root password is not needed.
To run a command which requires root privileges in a terminal:
prepend sudo in front of it. To get an interactive root shell, use sudo -i.
Manual page sudo_root(8) line 1
See also https://wiki.ubuntu.com/RootSudo
Limited free support is available via the sudo-users mailing list, see
http://www.sudo.ws/mailman/listinfo/sudo-users to subscribe or search
the archives.
Sudo commands summary
sudo apt-get install programname - install a program eg: instal a program called "prog", sudo apt-get install prog
sudo apt-get remove programname - uninstall a program
sudo apt-get autoremove - remove orphaned/surplus files
sudo apt-get update - updates system to latest release
sudo apt-get upgrade - upgrade to newer versions all systems listed in source files
sudo bash - run all commands as admin
sudo !! - repeat last command with admin privileges
sudo reboot - immediately reboot system
sudo poweroff - immediately shut-down system
gksudo command - start sudo visual dialog, GNOME,
enter password enter password for administrative access
gksudo nautilus - root file manager, GNOME, gain administrative access to Nautilus to modify the computer system
enter password
ifconfig - displays information network
iwconfig - displays information from wireless
sudo iwlist scan scan wireless networks
wade@wade-GCM-S2L:~$ sudo iwlist scan
[sudo] password for wade:
lo Interface doesn't support scanning.
eth0 Interface doesn't support scanning.
eth1 Interface doesn't support scanning.
sudo /etc/init.d/networking restart reset the network
ifup interface - bring online interface and configure network
with -h, --help, to show summary of options. For example,
:~$ ifup -h
Usage: ifup
Options:
-h, --help this help
-V, --version copyright and version information
-a, --all de/configure all interfaces marked "auto"
--allow CLASS ignore non-"allow-CLASS" interfaces
-i, --interfaces FILE use FILE for interface definitions
-n, --no-act print out what would happen, but don't do it
(note that this option doesn't disable mappings)
-v, --verbose print out what would happen before doing it
--no-mappings don't run any mappings
--force force de/configuration
ifdown interface - disable network interface
Command System.
lsb_release -a get the version of Ubuntu
uname -r get kernel version
uname -a get all the information kernel
Commands for Package Manager
apt-get update refresh updates available
apt-get upgrade update all packages
apt-get dist-upgrade version update
apt-get install pkg installing pkg
apt-get remove pkg uninstall pkg
apt-get autoremove removing packages obsotletos
apt-get -f install try to fix packages
dpkg configure -a try to fix a broken package
dpkg -i pkg.deb install file pkg.deb
(file) /etc/apt/sources.list list of repositories APT
Special packages for commands
ubuntu-desktop Setting the standard Ubuntu
ubuntu-minimal core earnings Ubuntu
ubuntu-standard the standard utilities Ubuntu
build-essential packages used to compile
linux-image-generic latest generic kernel image
linux-headers-generic latest headlines
Application commands
nautilus - open file Manager program
gedit - open text editor program
restart - restart the GNOME display manager to fix a crash, locked keyboard or locked mouse:
sudo /etc/init.d/gdm restart
start - start the Gnome program:
sudo /etc/init.d/gdm start
stop - stop the Gnome program:
sudo /etc/init.d/gdm stop
Service system commands
to start, stop or restart a service in ubuntu
for example, to stop or start the Apache Webserver:
/etc/init.d/apache2 stop
/etc/init.d/apache2 start
start service service to start work (Upstart)
stop service service to stop working (Upstart)
status service check if service is running (Upstart)
/etc/init.d/service start start service (SysV)
/etc/init.d/service stop stop service (SysV)
/etc/init.d/service status check service (SysV)
/etc/init.d/service restart reset service (SysV)
runlevel get current runlevel
Firewall commands
ufw enable turn on the firewall
ufw disable turn off the firewall
ufw default allow allow all firewall connections by default
ufw default deny drop all firewall connections by default
ufw status show current status of firewall rules
eg user@tomt-L:~$ ufw status
ERROR: You need to be root to run this script
wae@wae-GCM-S2L:~$ sudo ufw status
[sudo] password for user:
Status: inactive
ufw allow port to allow traffic on port through firewall
ufw deny port port block
ufw deny from ip ip block
To instal mulit-media codecs if you are using regular, stock Ubuntu:
sudo apt-get install ubuntu-restricted-extras
In addition, in order to play DVDs, you need to install libdvdcss by entering the following in a terminal:
sudo /usr/share/doc/libdvdread4/install-css.sh
For Ubuntu 12.04 LTS
Medibuntu (media, entertainment)
sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list
sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring
sudo apt-get --quiet update && sudo apt-get -y upgrade
update Synaptic to display third party repositories:
sudo update-apt-xapian-index
[ will take 45 seconds, or more ]
multimedia codecs
sudo apt-get -y install w32codecs ubuntu-restricted-extras (32bit)
sudo apt-get -y install w64codecs ubuntu-restricted-extras (64bit)
enable full DVD support
sudo apt-get -y install libdvdcss2 libdvdnav4 libdvdread4
sudo /usr/share/doc/libdvdread4/install-css.sh
To install the proprietary CODECs type the following in a terminal window.
32 bit
sudo apt-get -y install gstreamer0.10-pitfdll gstreamer0.10-ffmpeg gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse
64 bit
sudo apt-get -y install gstreamer0.10-ffmpeg gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse
For Ubuntu 11,
The command to install a full codec pack is:
sudo apt-get install ubuntu-restricted-extras
But this codec pack won't allow you to play original DVD movies that are encrypted by default. So again use the below commands to enable that as well.
sudo wget http://www.medibuntu.org/sources.list.d/natty.list –output-document=/etc/apt/sources.list.d/medibuntu.list
sudo apt-get update
sudo apt-get install medibuntu-keyring
sudo apt-get update
sudo -s
apt-get install libdvdcss2
cd /usr/share/doc/libdvdread4/
./install-css.sh
For Ubuntu 10
To install Mplayer media player
Open terminal from Applications->Accessories->Terminal and type:
sudo apt-get install mplayer*
To install w32codecs/w64codecs and libdvdcss2
First,use following commands to add Medibuntu’s repository to Ubuntu:
sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list
sudo apt-get --quiet update
sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring
sudo apt-get --quiet update
then,use apt-get command to install them from repository:
for amd64
sudo apt-get install w64codecs libdvdcss2
for i386
sudo apt-get install w32codecs libdvdcss2
If you don’t prefer the command line, you can also download deb packages for w32codecs/w64codecs and libdvdcss2 from:
http://packages.medibuntu.org/lucid/index.html
VLC media play installation instructions for Ubuntu 10.04
Open the terminal and run the following commands to install VLC 2.0 in Ubuntu 10.04:
sudo add-apt-repository ppa:n-muench/vlc2
sudo apt-get update && sudo apt-get install vlc
For Ubuntu 9
For i386 Users install Codecs using the following command
sudo apt-get install w32codecs libdvdcss2
The following command adds Medibuntu's repository to Ubuntu. It also adds Medibuntu's GPG key to your keyring, which is needed to authenticate the Medibuntu packages.
sudo wget http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list --output-document=/etc/apt/sources.list.d/medibuntu.list
sudo apt-get -q update
sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring
sudo apt-get -q update
To download and install VLC movie player:
% sudo apt-get update
% sudo apt-get install vlc browser-plugin-vlc
Ubuntu includes whichever VLC version was the latest at the time the Ubuntu release was frozen.
To format a CD-RW in Terminal use the following command:
cdrecord dev=/dev/hdc speed=10 blank=fast padsize=63s -pad -v -eject
You may have to change the "dev=" line depending upon your device
designation and you can change the speed number if you wish.
"blank=all" will give a complete format but takes some time.
Vi text editor is installed with Ubuntu along with Gedit text editor. Use Gedit instead as it is more familiar than Vi and not awkwar. To use Vi as an alternative, first open the file called viuse.txt so that full instructions are ready.
Change to the directory where the existing file is saved or a new file is to be saved.
user7@user7-271GZM-S2:~$ cd ~/Desktop
user7@user7-271GZM-S2:~/Desktop$ vi testvi
Vi oppens a window saying:
E325: ATTENTION
Found a swap file by the name ".testvi.swp"
owned by: user7 dated: Wed May 31 15:23:53 2017
file name: ~user7/Desktop/testvi
modified: YES
user name: user7 host name: user7-271GZM-S2
process ID: 2217
While opening file "testvi"
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r testvi"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".testvi.swp"
to avoid this message.
"testvi" [New File]
Press ENTER or type command to continue
That message says that a previous attempt to save a text file by the same name, testvi, failed to be saved. Press enter to open a typing and editing window.
If a saved file by the same name already exists, it will open
otherwise a new file by that name will open
a screen with tildes down the side.
Press i and type or edit the file.
Press ESC key and vivivi to open command mode. This is where to
enter commands to save the file.
Type a colon to open a command line at the bottom of the screen.
Type a command at the colon.
To save the file and exit, type wq
Or to quit without saving press ESC type vi then type :q and press enter key.
touch - To change a file's access and modification dates:
Right click the file in File Manager. File properties shows that a file called testlist has a modification date of June 5 and an access date of June 15.
user@user-H64C-ED4:~/Desktop/testfold$ touch testlist
Touch has changed both dates to June 19.
To create or make a new file with touch, first be sure that a file by the same name does not exist or touch will overwrite that file's dates. Change to the home directory by cd ~ so as not to overwrite any system file in the root / directory.
user@user-H64C-ED4:~/Desktop/testfold$ touch testtouch.txt
user@user-H64C-ED4:~/Desktop/testfold$ ls
bintest fruitsale listcut.txt memotestc testlist2 testtouch.txt
codetest fruitsale2 listtest tdout testlistk
dtop link1 memotest testlist testlistk2
user@user-H64C-ED4:~/Desktop/testfold$ gedit testtouch.txt
user@user-H64C-ED4:~/Desktop/testfold$
Click the tab in Gedit and start writing into the new file.
Git or git-dpm is a program to help a group of software developers coordinate their work on a project. Git-hub is a web-based git repository and hosting service.
Xterm is a generic terminal program. To start Xterm from Terminal, type the command xterm to open a separate terminal window. Lock the Xterm icon to the program bar.
The default terminal shell in most Linux distributions is Bash, bash, as used in some examples above.
test - Test is a command used in scripts which can be run by typing test but usually is run by typing a bracket [ . So do not call a shell script test. Type the command test instead of a [ .
This command tests whether 5 is bigger greater than 2.
user@user-H64C-ED4:~$ test 5 -gt 2 && echo "Yes"
Yes
user@user-H64C-ED4:~$
To find files which -m match being more + than 14 days old:
jack@jack-U-H:~$ sudo find ~/Desktop/testfold/ -mtime +14 | more
[sudo] password for jack:
/home/jack/Desktop/testfold/testlist2
/home/jack/Desktop/testfold/fruitsale
/home/jack/Desktop/testfold/listcut.txt
/home/jack/Desktop/testfold/testlistk
/home/jack/Desktop/testfold/tdout
/home/jack/Desktop/testfold/testlistk2
/home/jack/Desktop/testfold/fruitsale2
Other files shown below are newer.
jack@jack-U-H:~$ ls ~/Desktop/testfold/
bintest fruitsale listtest quailprice.png testlistk testtouch.txt
codetest fruitsale2 memotest tdout testlistk2
dtop listcut.txt memotestc testlist2 testshel
jack@jack-U-H:~$
To remove delete several directories at once:
Here all directories in the current folder with names beginning with fold are to be deleted.
jack@jack-U-H:~$ rmdir ~/fold*
xargs - To let tools like echo, rm and mkdir use standard input as arguments:
jack@jack-U-H:~/Music$ echo 'fold1 fold2 fold3' | xargs mkdir ; ls ~/Music/
fold1 fold2 fold3
jack@jack-U-H:~/Music$
There we used xargs to make three subdirectories in the current /Music directory.
To be safer with xargs, you can use the -t option to show how a command is about to be executed, and the -p option to prompt the user to execute it.
To show an error message if a command fails to do what it is asked to do, use a double pipe command:
user@user-U-H:~/Desktop/testfold$ ls
errors quailprice.png sshsh
ipdetect shtest The Seven Letters From Tibet 04. The Green Land.mp3
There is an .mp3 file with a long name. Run the move mv command to rename it in one word, tibet.mp3, with an added || command to give an error message.
user@user-U-H:~/Desktop/testfold$ mv "The Seven Letters From Tibet 04. The Green Land.mp3" tibet.mp3 || echo "Could not rename that file." >&2
No error message is shown as rm found and renamed the .mp3 file. Run that command again.
user@user-U-H:~/Desktop/testfold$ mv "The Seven Letters From Tibet 04. The Green Land.mp3" tibet.mp3 || echo "Could not rename that file." >&2
mv: cannot stat 'The Seven Letters From Tibet 04. The Green Land.mp3': No such file or directory
Could not rename that file.
The last line is the special error message. This time it was shown because remove could no longer find the file by its long name.
user@user-U-H:~/Desktop/testfold$ ls
errors ipdetect quailprice.png shtest sshsh tibet.mp3
user@user-U-H:~/Desktop/testfold$
To delete all files with test in their names from the current directory but show an error message if there are not such files to delete:
user@user-U-H:~/Desktop/testfold$ ls
errors ipdetect quailprice.png shtest sshsh tibet.mp3
There is one file with test in its name.
Here is an if then shell script.
user@user-U-H:~/Desktop/testfold$ bash ~/Scripts/delete.sh
user@user-U-H:~/Desktop/testfold$ ls
errors ipdetect quailprice.png sshsh tibet.mp3
The test file is deleted.
Run that script again.
user@user-U-H:~/Desktop/testfold$ bash ~/Scripts/delete.sh
rm: cannot remove './*test*': No such file or directory
No test files to delete in this directory.
user@user-U-H:~/Desktop/testfold$
There is the error message.
type - To show where Bash finds a program to run, use the type command.
user@user-U-H:~/Desktop/tfold$ type gedit
gedit is /usr/bin/gedit
user@user-U-H:~/Desktop/tfold$
The edit program is in the user binary directory.
To run a program or script that is not installed in a PATH directory, type the path to that program before its name.
user@user-U-H:~/Desktop/testfold$ bash ~/Scripts/delete.sh
$(...) - Command substitution is safer using the $(...) syntax, not the back tick ` syntax. So use $(...) and double quotes " instead of a tick ` with \\ backstrokes.
echo "$(echo "$(echo "words to say")")"
user@user-U-H:~$ echo "$(echo "$(echo "This is and example of an expansion.")")"
This is and example of an expansion.
user@user-U-H:~$
The double quotes tell Bash which spaces are not commands.
For safety, name only in lowercase all the shell variables you make. But name all environment variables in all uppercase. Use [@] as an array suffix but don't use [*].
To enable extended globs:
$ shopt -s extglob
To recover files from a working hard drive, boot Ubuntu live on CD and start Terminal then:
ubuntu@ubuntu:~$ cd ~/Documents
ubuntu@ubuntu:~/Documents$ ls
ubuntu@ubuntu:~/Documents$ cd /
ubuntu@ubuntu:/$ ls
bin cdrom etc initrd.img media opt rofs sbin srv tmp var
boot dev home lib mnt proc root selinux sys usr vmlinuz
ubuntu@ubuntu:/$ ls media
0b2e199f-8635-4d61-b3b1-011d2ad78102 Archives
ub
That is the name of the hard drive with an archive on it.
To change to a directory with spaces in its name, use " quotes or an asterisk * wildcard.
ubuntu@ubuntu:/$ cd /media/"0b2e199f-8635-4d61-b3b1-011d2ad78102 Archives"/
bash: cd: /media/0b2e199f-8635-4d61-b3b1-011d2ad78102 Archives/: No such file or directory
ubuntu@ubuntu:/$ cd /media/0b2e199f-8635-4d61-b3b1-011d2ad78102*/ ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$
To show which users have permission to read files in the directories of the archive drive, use the -l option for a long list:
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ ls -l ./
total 108
drwxr-xr-x 2 root root 4096 2019-06-29 22:00 bin
drwxr-xr-x 3 root root 4096 2019-06-29 22:00 boot
drwxr-xr-x 2 root root 4096 2019-06-29 21:58 cdrom
drwxr-xr-x 5 root root 4096 2010-10-07 16:13 dev
drwxr-xr-x 130 root root 12288 2019-06-30 00:16 etc
drwxr-xr-x 3 root root 4096 2019-06-29 21:58 home
lrwxrwxrwx 1 root root 33 2019-06-29 21:59 initrd.img -> boot/initrd.img-2.6.35-22-generic
drwxr-xr-x 16 root root 12288 2019-06-29 22:00 lib
Root, that is the administrator or superuser, has permission to rwx read write or execute files in the d directories, other - users do not.
To show all -a hidden subfolders and files in a directorym use the -all option.
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ ls -a ./home/username/
. Documents .gvfs .pulse-cookie
.. Downloads .ICEauthority Templates
.bash_logout .esd_auth .local .thumbnails
.bashrc examples.desktop Music Videos
.cache .gconf .nautilus .xsession-errors
.config .gconfd Pictures .xsession-errors.old
.dbus .gnome2 .profile
Desktop .gstreamer-0.10 Public
.dmrc .gtk-bookmarks .pulse
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$
Those with names that begin with a stop . are otherwise hidden from view in the directory.
To access a hidden directory:
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ ls -a ./home/username/.thumbnails/ | more
ls: cannot open directory ./home/username/.thumbnails/: Permission denied
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ sudo ls -a ./home/username/.thumbnails/ | more
. .. fail normal
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ sudo ls -a ./home/username/.thumbnails/
. .. fail normal
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$
To give every user the right to read, write or execute the .thumbnails directory, use chmod with the following options:
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ sudo chmod a+rwx ./home/username/.thumbnails/
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$
To reveal a hidden file or directory, rename it without the dot . :
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ sudo mv ./home/username/.thumbnails/ ./home/username/thumbnails/
List shows that the directory is renamed without the full stop.
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ ls -a ./home/username/
. Documents .gvfs .pulse-cookie
.. Downloads .ICEauthority Templates
.bash_logout .esd_auth .local thumbnails
.bashrc examples.desktop Music Videos
.cache .gconf .nautilus .xsession-errors
.config .gconfd Pictures .xsession-errors.old
.dbus .gnome2 .profile
Desktop .gstreamer-0.10 Public
.dmrc .gtk-bookmarks .pulse
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$
Bash colours the name of that thumbnails directory green to show that users other than the owner of the directory can write to it now.
List shows the thumbnails directory is empty.
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ sudo ls -a ./home/username/thumbnails/
. .. fail normal
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$
sudo: cd: command not found
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102$ cd ./home/username/thumbnails/
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username/thumbnails$ ls
fail normal
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username/thumbnails$
To rewrite long commands, press the up arrow key to scroll previous commands then edit A previous command to suit.
To use a wildard * again to edit out a space in a directory names:
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username/thumbnails$ cd /media/0b2e199f-8635-4d61-b3b1-011d2ad78102*/home/username/
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$
To hide a directory or file, rename it starting with a .filename full stop.
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$ sudo mv thumbnails .thumbnails
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$
The thumbnails directory is hidden again.
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$ ls -a
. Desktop .gconfd Music Templates
.. .dmrc .gnome2 .nautilus .thumbnails
etc ...
.dbus .gconf .local .pulse-cookie
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$
To show who has permission to use a .hidden directory:
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$ sudo ls -l .thumbnails
total 8
drwx------ 3 1000 1000 4096 2019-06-29 23:54 fail
drwx------ 2 1000 1000 4096 2019-06-30 00:18 normal
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$
The d means directory, not a file.
Or ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$ sudo ls -l .cache
total 40
drwx------ 2 1000 1000 4096 2019-06-30 00:13 compizconfig
drwx------ 2 1000 1000 4096 2019-06-30 00:13 dconf
-rw-r--r-- 1 1000 1000 16384 2019-06-29 22:05 event-sound-cache.tdb.fa383ea772837e4d986f620800000006.i686-pc-linux-gnu
-rw-r--r-- 1 1000 1000 416 2019-06-30 00:13 indicator-applet.log
-rw-r--r-- 1 1000 1000 301 2019-06-30 00:13 indicator-applet-session.log
drwxr-xr-x 2 1000 1000 4096 2019-06-29 22:06 update-manager-core
drwx------ 2 1000 1000 4096 2019-06-29 22:00 wallpaper
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$
To give only the owner user permission to read, write to or execute a file, directory or script:
$ sudo chmod u+rwx,g-rwx,o-rwx ./.thumbnails
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$ sudo chmod u+rwx,g-rwx,o-rwx ./.thumbnails
ubuntu@ubuntu:/media/0b2e199f-8635-4d61-b3b1-011d2ad78102/home/username$
Only user has a + plus, groups and others have a minus - .
To replace a forgotten login password for Linux:
Boot the 2nd Slackware disk live on CD.
Log in as root with no password.
darkstar:# cd /mnt
darkstar:mnt/# mount /dev/hda /mnt
already mounted or busy
# cd /mnt/etc
no such file or directory
# find /*/shadow*
/etc/shadow
That found the file called shadow which had the encrypted password. Need to edit shadow but Gedit is not with Slackware so use Pico editor.
darkstar:/# pico /etc/shadow
root::9804:0:::::
etc ...
adm:*:9797:0:::::
guest:*:9797:0:::::
The root's password would be a number between the first two colons after root but no number is there. Root's password for Linux on the CD is already deleted.
^g Ctrl-g to get help in Pico.
^v CTRL-v for next page.
^O to output file and save it.
^X to save file and exit Pico.
darkstar:/# exit
Logged out
Login again as root with no password.
You need to find Linux on the hard drive, not on the CD, and delete the password of root there in the file called shadow.
darkstar:/# df
That shows the cdrom is called device /dev/hdb and it is mounted in the directory called /cdrom. The hard drive is not mounted yet.
Commands lsblk and blkid do not work with Slackware Linux.
This Linux kernel does not seem to recognise the format of the partition of the hard drive and cannot mount it. Kernel is looking for a Fat32 partition but the partition must be formatted Ext 4.
Try with Ubuntu live CD instead.
To list and show mounted filing systems:
mount -l
commandprompt:~$ mount -l
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1999368k,nr_inodes=499842,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=404116k,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
etc ...
That shows the partition of the main hard drive is called device /dev/sda1, is formatted ext-4 and is mounted on point / , that is the root directory.
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
commandprompt:~$
To scroll in Terminal, drag the sidebar.
Option -o is to list items separated by commas.
Option -l shows labels.
To mount all filing systems:
mount -a
To unmount all filing systems not in use:
umount -a.
Usually do not use an -f option to force drives in use to be unmounted.
To remount an already mounted filing system so as to change configurations:
$ mount -o remount /mnt
To unmount that: umount /mnt
To unmount a drive device file system:
umount /mountpoint
commandprompt:~$ umount /mnt/hdd
umount: /mnt/hdd: not mounted
commandprompt:~$ ls /mnt
hdd
Here no drive was mounted. The mount point /hdd is still there.
To make a mount point for a drive device:
commandprompt:~$ ls /mnt
commandprompt:~$ mkdir /mnt/hdd
mkdir: cannot create directory ‘/mnt/hdd’: Permission denied
commandprompt:~$ sudo mkdir /mnt/hdd
[sudo] password for username:
commandprompt:~$ ls /mnt
hdd
commandprompt:~$
To remove a mount point:
commandprompt:~$ sudo rmdir /mnt/hdd
commandprompt:~$ ls /mnt
To show whether a file system is mounted for read only ro or read and write rw, use the verbose -v option:
commandprompt:~$ mount -v
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
... etc
Here the hard drive sda1 is mounted for rw read and write.
To check partitions, run fdisk:
commandprompt:~$ sudo fdisk -l
[sudo] password for username:
Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
... etc
Disk /dev/sda: 117.4 GiB, 126034206208 bytes, 246160559 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc7f51bf9
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 241977343 241975296 115.4G 83 Linu
/dev/sda2 241979390 246159359 4179970 2G 5 Exte
/dev/sda5 241979392 246159359 4179968 2G 82 Linu
etc ..
/dev/sdd5 62525043 78156224 15631182 7.5G b W95
commandprompt:~$
openssl - To encrypt a file and give it a password: -
username@username-desktop:~/Desktop$ openssl enc -aes-256-cbc -in testhide -out testhidee
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
username@username-desktop:~/Desktop$ ls
hide testhide testh.rvr zipencryptestc.zip
testh testhide3.txt zipcloak zipencryptest.zip
testh3.rvr testhidee zipencryptestb.zip zipsudo
username@username-desktop:~/Desktop$ gedit testhidee
Gedit shows encryption.
慓瑬摥彟铛ṟၢ笯ᣩ턪ⱀ厗㕥䑷衟㜌晘儈ۆ듦矂ⷀ橺ᤒ뺹ꮀ
Nautilus file manager does not show extensions for text files or an .enc extension for an encrypted text file. So type an e at the end of the filename to show that the file is encrypted.
To encrypt a file in a directory other than the current one:
username@username-ID:~$ openssl enc -aes-256-cbc -in ~/Desktop/testenc -out ~/Desktop/testence
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
username@username-ID:~$ ~/Desktop/
To encrypt a file in a directory on a second hard drive:
First change cd to the directory which holds the file.
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Desktop$ openssl enc -aes-256-cbc -in gpgpswd -out gpgpswde
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Desktop$ ls
2DO finefriend backscript gpgpswd gruberrorc
chmoderrorc.png gpgpswde linuxsudo11
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Desktop$
The encrypted -out file is the one named with an e on the end. The original file can now be removed. A string of characters like aes-128-ecb in the command is a cipher code, not various options.
To decrypt a file:
username@username-desktop:~/Desktop$ openssl enc -d -aes-256-cbc -in testhidee -out testhided
enter aes-256-cbc decryption password:
username@username-desktop:~/Desktop$ ls
hide testhide testhidee zipencryptestb.zip zipsudo
testh testhide3.txt testh.rvr zipencryptestc.zip
testh3.rvr testhided zipcloak zipencryptest.zip
username@username-desktop:~/Desktop$ gedit testhided
Gedit shows the original text.
This file is now for encryption with ssl.
Best practice would be to delete the original file after it was encrypted and to decrypt it back to its original name, without the d at the end. An encrypted file stays encrypted even after it is decrypted as a copy. The decrypted file is a copy and may be deleted or edited and encrypted again.
To decrypt a file in another directory:
username@username-ID:~$ openssl enc -d -aes-256-cbc -in ~/Desktop/testence -out ~/Desktop/testencd
enter aes-256-cbc decryption password:
username@username-ID:~$
Gedit opened this decrypted file.
To decrypt a file with an unknown extension:
Type the filename as it is on the ls list, without an extension.
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Desktop$ openssl enc -d -aes-256-cbc -in gpgpswde -out testdecrypt
enter aes-256-cbc decryption password:
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Desktop$
To edit a decrypted file then re-encrypt it over the old encryption:
username@username-desktop:~/Desktop$ gedit testhidee
username@username-desktop:~/Desktop$ openssl enc -aes-256-cbc -in testhided -out testhidee
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
username@username-desktop:~/Desktop$ ls
hide testhide testhidee zipencryptestb.zip zipsudo
testh testhide3.txt testh.rvr zipencryptestc.zip
testh3.rvr testhided zipcloak zipencryptest.zip
username@username-desktop:~/Desktop$ gedit testhidee
Salted__â#y®^`$#¹t°}5@»#ÞàÌÎë#öå
}Äh#3¬Î###ªq£sµÑ8º ##¿¡ÒA##ŽÁc%\°Ôxê#â##bI#!'9#Ò·Ôf?€¶m×àFÍå Hœ;ÅéyuÜÙó`))mÕ?ívV
Here the edited file is bigger now than it was when first encrypted.
The decrypted copy should be removed rm.
A re-encrypted file or any file encrypted with the same name will overwrite the old encryption file without warning.
Do not run Openssl on a zip file, or a renamed zip file, because that won't work and will ruin the file. If an e is typed at the end of the ssl -out filename, the original file will still be alright.
To learn about key password pairs to encrypt files, search this file for gen-key. Search for openssl to learn how to protect files with a single private password.
-zip To remove or delete original files which have been zipped or encrypted:
user@user-desktop:~/Desktop$ rm zipencryptestb
user@user-desktop:~/Desktop$ ls
zipcloak zipencryptest zipencryptestb.zip zipencryptest.zip zipsudo
user@user-desktop:~/Desktop$ rm zipencryptest
user@user-desktop:~/Desktop$
-unzip To extract unzip all the files out of a winzip file on a floppy disk fd:
Change to the directory into which you want to copy the files.
commandprompt:~/Desktop$ cd ~/Desktop/testfold/
Mount the floppy disk.
commandprompt:~/Desktop/testfold$ mount /media/floppy
Run the unzip command. Here the name of the zip file is construct.
commandprompt:~/Desktop/testfold$ unzip /media/floppy/construct.zip
Archive: /media/floppy/ffcaao.zip
inflating: construction.JPG
inflating: c00058.jpe
inflating: c00115.jpe
... etc
see list of all the files extracted.
Unmount the FD when finished with it.
commandprompt:~/Desktop/testfold$ umount /media/floppy/
To compress zip one file in the current directory:
commandprompt:~/Desktop/testfold$ zip ccimg.zip ./ccimg.gif
The new file is to be called ccimg.zip. The file to be compressed is called ccimg.gif.
adding: ccimg.gif (deflated 2%)
commandprompt:~/Desktop/testfold$ ls
00140.jpe BRIS1.JPG
0148.jpe bugtest
05099g.jpg bugtestc
d11b.jpg ccc.jpg
r3tt.jpg cciimg.gif
iALEXIS070.JPG ccimg.gif
ALEXIS0C71.JPG ccimg.zip
... etc
The old file now may be deleted.
To compress several files, use the command as above and list the names of the files with a space but no punctuation between them.
To automatically move the files out of the directory being zipped and into the zip file, type the -m option.
zip -m file1.txt file2.txt file3.txt etc
The old files are automatically deleted from where they were.
-unzip - To decompress or unzip a zipped file into the present directory:
commandprompt:~/Desktop/testfold$ unzip ccimg.zip
Archive: ccimg.zip
replace ccimg.gif? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: ccimg.gif
commandprompt:~/Desktop/testfold$
Here the unzipped file overwrote and replaced the original file by the same name. The unzipped file can be deleted because a copy of it is stored in the zip file.
To hide a file by giving it a password so nobody else can see it, run zip with the -e for encrypt option.
commandprompt:~/Desktop/testfold$ zip -e bugteste.zip bugtest
Enter password:
Verify password:
adding: bugtest (deflated 57%)
commandprompt:~/Desktop/testfold$
An e may be added to the end of a zip filename to show that it is encrypted.
Best to delete the original file.
commandprompt:~/Desktop/testfold$ rm bugtest
commandprompt:~/Desktop/testfold$ ls
04043.jpe br224.jpe
04148.jpe bugtestc
05099g.jpg bugteste.zip
11b.jpg ccc.jpg
To show what is in a zipped file, use unzip.
commandprompt:~/Desktop/testfold$ unzip bugteste.zip
Archive: bugteste.zip
[bugteste.zip] bugtest password:
inflating: bugtest
commandprompt:~/Desktop/testfold$ gedit bugtest
The unzipped file reads -
Destructive bug error
Merely by typing one space before the name of the user to be deleted is an error which deletes the whole home directory ... etc
To save an edited file and overwrite its zip file:
commandprompt:~/Desktop/testfold$ zip -e bugteste.zip bugtest
Enter password:
Verify password:
updating: bugtest (deflated 57%)
To overcome an error message like "Could not display; the location is not a folder": in graphic mode, right click the zip file and choose to open it with the archive manager instead of the file manager.
To remove or delete a file from within a zip archive, use the -d option.
$ zip -d archivename.zip filename
user@user-12ri:/media/160gbSamsung/home/username/.locker$ zip -d ide1438e.zip ide1438/video.mp3
deleting: ide1438/video.mp3
user@user-12ri:/media/160gbSamsung/home/username/.locker$
The full filename must be typed as it is listed by zip scan files -sf. Zip keeps the files in a a subdirectory named when the zip was made.
To delete more than one file from a zip archive, run zip -r with the names of all the files to be deleted, separating each filename with a space but no comma.
$ zip -d archivename.zip subdirectory/filename subdirectory/file2 subdirectory/file3
Here the zip and subdirectory were named after the original directory which held the files to be zipped.
user@user-12ri:/media/160gbSamsung/home/username/.aqk/.etol$ sudo zip -d picr1.zip picr1/bbh12.jpg picr1/twtw04.jpg picr1/lss04.jpg
deleting: picr1/bbh12.jpg
deleting: picr1/lss04.jpg
deleting: picr1/twtw04.jpg
user@user-12ri:/media/160gbSamsung/home/username/.aqk/.etol$
To delete a group of files from an archive using a wildcard:
First run zip scan-files or browse the extracted directory to find and copy the names of the files to be deleted and paste them into the command line. Here the files to be deleted are all those with names starting with the letter h and one other file named.
user@user-12ri:/media/160gbSamsung/home/username/.aqk/.etol$ zip -d picr1.zip picr1/h* picr1/546122.gif
user@user-12ri:/media/160gbSamsung/home/username/.aqk/.etol$ sudo zip -d picr1.zip picr1/h* picr1/546122.gif
To zip a folder on a second hard drive:
Mount the second hard drive, which here is called Samsung.
user@user-945GCM-S2L:/$ ls /media
160gbSamsung apt floppy floppy0 red8gbusb
Change to the directory holding the folders to be zipped.
user@user-945GCM-S2L:/$ cd /media/160gbSamsung/
user@user-945GCM-S2L:/media/160gbSamsung$ ls
bin dev initrd.img media proc selinux tmp vmlinuz
boot etc lib mnt root srv usr
cdrom home lost+found opt sbin sys var
user@user-945GCM-S2L:/media/160gbSamsung$ cd ./home/user/Downloads/
user@user-945GCM-S2L:/media/160gbSamsung/home/user/Downloads$ ls
Adeld026.jpg
Adeld049.jpg
scenes9798
...etc ...
vide1438e.zip
vide1438x
user@user-945GCM-S2L:/media/160gbSamsung/home/user/Downloads$
There is an encrypted e.zip archive which has been extracted into a folder with the same name as the original folder then renamed with an x for extracted.
The folder there to be zipped is called scenes9798.
Run the zip command:
$ zip -re1Tm scenes9798e.zip scenes9798/
Remember the password you have chosen.
That command zipped and encrypted the folder with all the files in it then removed the old folder leaving in its place the new zip folder.
WARNING: the zip command and its -f, -u and file sync fs options will overwrite and delete files of the same name but different size or date without prompting - even if those files are quite different from each other inside. A long text file written months before could be replaced by a short file of the same name written yesterday. A tiny thumbnail gif file could replace a large, high resolution image of the same name. Some quite different files from different computers and drives may share the same name. Zip may not work as intended when time zones change, like for daylight saving. A change in time settings may cause Zip to back up all files instead of only those which have changed since the last backup. Other backup programs too may make the same mistakes. Zip encryption is weak whereas SSL encryption is strong.
To zip all files in the current present directory:
zip zipname *
commandshell:~/Desktop/testfold/dirtest$ zip dirtest *
adding: 050999g.jpg (deflated 1%)
adding: 11b.jpg (deflated 5%)
adding: ap_niki.jpe (deflated 0%)
adding: banner.jpe (deflated 3%)
adding: bugtestc (deflated 66%)
adding: elmga.jpg (deflated 0%)
adding: errors (deflated 91%) ... etc
List shows the new zip file called dirtest.zip.
commandshell:~/Desktop/testfold/dirtest$ ls
00043.jpe ccimg.gif fr125.jpg ... etc
11b.jpg br224.jpe dirtest.zip sshsh ... etc
To empty all * files out of a directory:
username@username-ID:~$ ls .locker/encrypt/gnupg gpgremove pgphowcut sudogpg
gpghow keyring pgpkey
username@username-ID:~$ rm .locker/encrypt/*
username@username-ID:~$ ls .locker/encrypt/
username@username-ID:~$
To change the name of a directory or zip archive, run the move mv command.
commandshell:~/Desktop/testfold$ mv ./testfold/ ./dirtest/
commandshell:~/Desktop/testfold$ ls
dirtest testdire.zip testfolde.zip
commandshell:~/Desktop/testfold$
To automatically remove the original directory after zipping the files in it, use the -Tm options. T tests the zip archive before -m moves the files out of the original directory and into the zip.
Change directories cd into the directory which holds the files to be zipped, then run this command:
zip -Tm zipname *
commandshell:~/Desktop/testfold/dirtest$ zip -Tm dirtest.zip dirtest *
... etc ... zip warning: name not matched: dirtest
updating: 00043.jpe (deflated 0%)
updating: 00058.jpe (deflated 1%)
updating: tibet.mp3 (deflated 2%)
test of dirtest.zip OK
commandshell:~/Desktop/testfold/dirtest$ ls
dirtest.zip
commandshell:~/Desktop/testfold/dirtest$
All files but the zip have been removed from the directory.
Scan files -sf shows that all the files are moved into the zip file.
commandshell:~/Desktop/testfold/di$ zip -sf dirtest.zip
Archive contains:
8043.jpe
50058.jpe
0599g.jpg ... etc
quailprice.png
sshsh
tibet.mp3
Total 40 entries (20661545 bytes)
commandshell:~/Desktop/testfold/dirtest$
To recursively zip all the files in the current directory and the files in its subdirectories:
zip -r zipname.zip .
The last dot means current local directory.
commandshell:~/Desktop/testfold/dirtest$ cd ~/Desktop/testfold/
commandshell:~/Desktop/testfold$ ls
dirtest testdire.zip testfolde.zip
commandshell:~/Desktop/testfold$ zip -r bigzipper.zip .
adding: dirtest/ (stored 0%)
adding: dirtest/dirtest.zip (stored 0%)
adding: testdire.zip (stored 0%)
adding: testfolde.zip (stored 0%)
commandshell:~/Desktop/testfold$ ls
bigzipper.zip testdire.zip
dirtest testfolde.zip
commandshell:~/Desktop/testfold$
There is the new bigzipper archive with the subdirectory in it.
To freshen a zip archive, use option -f to only copy into the archive files that have been changed.
To update a zip archive, use the -u option to only copy new and changed files into the archive.
zip -u archivename.zip filename.pdf
That command updates the existing archive and adds a new .pdf file to it.
To refresh a zip archive so that only newly edited files are added to it, use the -f option.
To date the zip archive as old as the latest file in it, use the lowercase -o option.
To test the integrity of a zip file or archive, use the capital -T option.
commandprompt:~/Desktop/testfold$ zip -T ccimg.zip
test of ccimg.zip OK
To test a zip file in gui graphic mode, open Files manager, browse to the zip file, double click the zip icon, click extract, select a destination directory or let it extract in the current directory, extract the zipped folder, double click the folder and see the list of files inside it, click a file to open it.
To scan the files in a zip archive and list their names, use the -sf option.
commandprompt:~/Desktop/testfold$ zip -sf ccimg.zip
Archive contains:
ccimg.gif
Total 1 entries (27658 bytes)
commandprompt:~/Desktop/testfold$
This zip has only one file in it.
To move directories into a zip archive, -u update the archive this way:
Change to the directory holding the archive. Here two folders to be added to the archive are in the same directory. This update command tells zip to copy any file or directory called test* in the current directory into the zip archive.
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ zip -u testinge.zip test*
adding: test2/ (stored 0%)
adding: test3/ (stored 0%)
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ ls -a
. .. test2 test3 testinge.zip
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ zip -sf testinge.zip
Archive contains:
testing/
test2/
test3/
Total 3 entries (0 bytes)
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$
The subdirectories called test2 and 3 are now copied into the zip and can be removed from the testfold directory.
The recursive -r option would need to be added to the update commands above to keep any files in the folders.
To recursively update a zip archive:
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ zip -ru testinge.zip *
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ zip -sf testinge.zip
Archive contains:
testing/
test2/
test3/
test2/gruberror
test2/gruberrorc
test3/nanouse
testing/unziphow
testing/finefriend
testing/fcrackzip
Total 9 entries (10322 bytes)
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$
Zip scan files shows that in the archive are now three folders which hold the six files named. New folders automatically overwrite folders of the same name in the zip.
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ ls -l
total 20
drwxrwxr-x 2 username username 4096 Aug 24 08:15 test2
drwxrwxr-x 2 username username 4096 Aug 24 08:15 test3
drwxrwxr-x 2 username username 4096 Aug 24 09:23 testing
-rw-rw-r-- 1 username username 5438 Aug 24 09:23 testinge.zip
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$
Copies of the folders are left in the main folder they need to be deleted for security.
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ zip -Tm testinge.zip
test of testinge.zip OK
Here the -m remove option did not remove the original copies from the folder. They must be deleted with rm and rmdir.
To delete files in a zip archive, use the -d option.
commandprompt:~/Desktop/testfold$ zip -d bugteste.zip bugtest
deleting: bugtest
zip warning: zip file empty
commandprompt:~/Desktop/testfold$
Here the only file in the zip was removed.
If a file in an archive on a floppy disk is to be deleted, it is often easier to move the zip archive to an empty directory on the hard drive. Work on the zip on the hard drive then move it back to overwrite the zip on the floppy.
To show the user permissions of the locker directory:
Here the locker is in the root user's directory on a second hard drive.
user@user-5CID:~$ cd /media/160gbSamsung/home/username/
user@user-5CID:/media/160gbSamsung/home/username$ ls -al
total 308 etc ...
dr-------- 13 username username 20480 2019-09-19 08:07 .locker
drwx------ 3 username username 4096 2013-07-23 15:41 .mission-control
drwx------ 4 username username 4096 2013-07-23 14:11 .mozilla
The sudo user has permission to read only.
To lock the locker:
user@user-5CID:/media/160gbSamsung/home/username$ chmod ugo=--------- .locker/
user@user-5CID:/media/160gbSamsung/home/username$ ls -altotal 308 etc ...
drwxr-xr-x 3 username username 4096 2013-07-23 14:01 .local
d--------- 13 username username 20480 2019-09-19 08:07 .locker
drwx------ 3 username username 4096 2013-07-23 15:41 .mission-control
Now no user has any permission to access the locker.
To unlock the locker:
user@user-5CID:/media/160gbSamsung/home/username$ chmod u=rwx------ .locker/
user@user-5CID:/media/160gbSamsung/home/username$ ls -al
total 308
drwx------ 13 username username 20480 2019-09-19 08:07 .locker
drwx------ 3 username username 4096 2013-07-23 15:41 .mission-control
Now only the root user can read amd write to the locker directory.
To hide the locker: in file manager, deselect show hidden files. The locker names starts with a dot to hide it.
To show the locker: in file manager, select show hidden files.
To access all directories and files with file manager: click places, computer, copy the computer icon to the desktop as a link.
To list what is in the locker:
First unlock it.
user@user-5CID:/media/160gbSamsung/home/username$ ls .locker/
foldtest id978 ... etc zips
icr1.xyz id986 ics9798 ide1438e.xyz
To check the locker:
user@user-5CID:/media/160gbSamsung/home/username$ cd .locker/
bash: cd: .locker/: Permission denied
Or user@user-5CID:/media/160gbSamsung/home/username$ cd /media/160gbSamsung/home/username/.locker/
bash: cd: /media/160gbSamsung/home/username/.locker/: Permission denied
The locker is locked.
To open the locker:
First unlock and change to the locker directory.
user@user-5CID:/media/160gbSamsung/home/username$ cd .locker/
user@user-5CID:/media/160gbSamsung/home/username/.locker$ ls
foldtest id978 etc ... icr1.xyz id986 ics9798 ide1438.xyz
Root user can now access the files in the locker.
To tidy the locker:
The only files in the locker should be ssl encrypted files, zip encrypted files and one or two directories currently being worked on. Other directories should be zipped as files. Remove unzipped directories which are copies of zips. Both ssl and zip encrypted files are password protected. Directories should be zipped with the -m option to remove the original directory and its files. Zip files have the same names as the directories they replace.
To remove a directory from the locker, list it and make sure there are no zip files in it, remove the files in it then remove the directory:
user@user-5CID:/media/160gbSamsung/home/username/.locker$ rm p*/*
user@user-5CID:/media/160gbSamsung/home/username/.locker$ rmdir p*/
Those two commands removed all directories with names starting with p.
File recovery programs can recover many zip files even after they have been removed or deleted but the zips still cannot be opened without a password. Password hacking programs can open most zip files.
To zip a directory in the locker:
Unlock the locker.
Move or cut and paste the directory into the locker.
user@user-5CID:~$ cd /media/160gbSamsung/home/username/.locker/
user@user-5CID:/media/160gbSamsung/home/username/.locker$ ls
icr1.xyz ics9779.zip id978 karate
ics9779 ics9798 ide1438.xyz
user@user-5CID:/media/160gbSamsung/home/username/.locker$
The directory to be zipped here is called karate.
user@user-5CID:/media/160gbSamsung/home/username/.locker$ zip -re1Tm karate.zip karate/
Enter password:
Verify password:
adding: karate/ (stored 0%)
adding: karate/japa.PDF (deflated 3%)
adding: karate/japkarate (deflated 33%)
adding: karate/japa1.BMP (deflated 44%)
[zifs2cIX] karate/japa.PDF password:
test of karate.zip OK
user@user-5CID:/media/160gbSamsung/home/username/.locker$
To mask a zip archive file, rename it with a different extension. That extension should be the same for all masked zips and should be remembered like a password. Choose an extension that will stop the file from opening.
user@user-5CID:/media/160gbSamsung/home/username/.locker$ mv karate.zip karate.xyz
user@user-5CID:/media/160gbSamsung/home/username/.locker$ ics9779.zip id978 karate.xyz ics9779 ics9798 ide1438.xyz
user@user-5CID:/media/160gbSamsung/home/username/.locker$
To mask the locker, rename it something that makes it look like something other than what it is. Remember the new name like a password.
To unzip a zip file:
Rename it with the .zip extension.
user@user-5CID:/media/160gbSamsung/home/username/.locker$ mv karate.xyz karate.zip
user@user-5CID:/media/160gbSamsung/home/username/.locker$ unzip karate.zip
Archive: karate.zip
creating: karate/
[karate.zip] karate/japa.PDF password:
inflating: karate/japa.PDF
inflating: karate/japkarate
inflating: karate/japa1.BMP
user@user-5CID:/media/160gbSamsung/home/username/.locker$ lsicr1.xml ics9779.zip id978 karate
ics9779 ics9798 ide1438.xml karate.zip
user@user-5CID:/media/160gbSamsung/home/username/.locker$
Zip automatically removed the original karate folder and unzip restored it. The original folder should be removed again after use because it is already in a zip archive.
Mask the zip again.
To list what files are in a zip archive:
user@user-5CID:/media/160gbSamsung/home/username/.locker$ zip -sf karate.zip
or zip -sf karate.xyz
Archive contains:
karate/
karate/japa.PDF
karate/japkarate
karate/japa1.BMP
Total 7 entries (26490383 bytes)
user@user-5CID:/media/160gbSamsung/home/username/.locker$
Zip scans and lists the files even if the extension of the archive has been changed. Bash list command cannot list the files in a zip.
To rename all .zip files in the locker as .xyz files:
rename 's/\.zip$/.xyz/' *
user@user-5CID:/media/160gbSamsung/home/username/.locker$ ls
id978 locked3.zip newdire.zip
ics9779.zip id986.xml lockall.zip locked.zip
ics9798 locked2.zip newdire2.zip
user@user-5CID:/media/160gbSamsung/home/username/.locker$
user@user-5CID:/media/160gbSamsung/home/username/.locker$ rename 's/\.zip$/.xyz/' *
user@user-5CID:/media/160gbSamsung/home/username/.locker$ ls
id978 locked3.xyz newdire.xyz
ics9779.xyz lockall.xyz locked.xyz
ics9798 ide1438.xml locked2.xyz newdire2.xyz
user@user-5CID:/media/160gbSamsung/home/username/.locker$
To rename .xyz files back to their original .zip extensions:
user@user-5CID:/media/160gbSamsung/home/username/.locker/foldtest/ics9779$ rename 's/\.xyz$/.zip/' *
To store files in the locker:
All files are collected into directories. Directories are moved into the locker. There they are zipped as archives one at a time. Archives are named the same as the directories zipped. Then Zip extensions are renamed. All zips are renamed with the same extension.
To store single files:
Single files are encrypted with Openssl and kept in relevant directories other than the zip.
To update a zip archive by adding directories and files to it:
Here the archive happens to be called append.zip and two directories are added to it.
$ zip -u -r append.zip ics9798 id978
The -r recursive option must be typed separate from the -u update option for Zip.
user@user-5CID:/media/160gbSamsung/home/username/.locker$ zip -u -r append.zip ics9798 id978
The -u option is for updating and the unzip command is for extracting.
To check that an archive has been updated:
user@user-5CID:/media/160gbSamsung/home/username/.locker$ zip -sf append.zi
List of all the update files.
id978/lyyl04.wmv
id978/csw02.wmv
id978/blb02.mpg
... etc ...
Total 17 entries (3052706093 bytes)
user@user-5CID:/media/160gbSamsung/home/username/.locker$
Without the recursive -r option in the command, Zip would add the folders empty.
/username/.locker$ zip -sf append.zip ics9798/
Would Add/Update:
ics9798/
Total 1 entries (0 bytes)
user@user-5CID:/media/160gbSamsung/home/username/.locker$
The directory in the zip is empty.
To check that the right files are going to be zipped into an archive, add an -sf option:
zip myfilename.zip -r /home/music/ -sf
This next command would tell Zip to extract all the files out of the two directories and add them into the archive, but without the two directories.
zip -u append.zip ics9798/* id978/*
To unzip one of a few directories in an archive:
user@user-5CID:/media/160gbSamsung/home/username/.locker$ unzip append.zip ics9798/*
List of files extracted.
inflating: ics9798/k120.jpg
inflating: ics9798/vov3.jpg
inflating: ics9798/y9m3.jpg
... etc ...
user@user-5CID:/media/160gbSamsung/home/username/.locker$
To list the extracted files:
user@user-5CID:/media/160gbSamsung/home/username/.locker$ ls ics9798
List shows all the files in the extracted directory called ics9798.
Zip options
-r recursively
-e encrypt
-1 level of encryption
-T test
-m remove directory
-d delete from zip
-n never overwrite files
-o overwrite without prompting
To change cd to an archive directory called locker on a second hard drive, change to the mount point /media/, list to find the names of subdirectories and change until reaching the locker.
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/
Here in this example the current directory is called testfold/ and it holds three subfolders.
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ ls
ics9779 ics9798 id978
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ zip -re1Tm lockall.zip ./*/
adding: id978/snns02.mpg (deflated 9%)
adding: id978/all.mp4 (deflated 3%)
adding: id978/hooh03.mpg (deflated 9%)
adding: id978/ipo004.wmv (deflated 1%)
adding: id978/cs003.wmv (deflated 1%)
adding: id978/snns03.mpg (deflated 9%)
adding: id978/sc002.wmv (deflated 2%)
adding: id978/2017-10-08-7490496.mp4 (deflated 0%)
...etc
[ziHXqWMq] ics9779/ffk10.jpg password:
test of lockall.zip OK
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ lslockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$
The three folders with all their files are moved into the zip archive. The three folders are empty and the files are loose in the zip archive. Yet Zip can extract one folder at a time by copying only the files which belong in that folder.
To lock the zip:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ sudo chmod ugo=--------- ./lockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ ls -al
total 2956420
drwxr-xr-x 2 username username 4096 2019-09-14 12:12 .
drwx------ 12 username username 20480 2019-09-14 11:07 ..
---------- 1 username username 3027342705 2019-09-14 12:11 lockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$
Or omit the ./ as it is not needed for a file in the current directory.
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ sudo chmod ugo=--------- ics9779.zip
[sudo] password for username:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ ls -l ics9779.zip
---------- 1 username username 238889163 2019-09-15 14:44 ics9779.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$
Options are explained in earlier examples in linoxsudo12.txt.
Any user trying to open the zip will see an error message like:
An error occurred while loading the archive.
Sudo user must change the mode of permissions on the archive to open it. He can do this easily be clicking the zip icon in file manager, selecting properties then selecting read and write from the drop list, or
To unlock a zip archive:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ sudo chmod ugo=rw------- ./lockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ ls -altotal 2956420
drwxr-xr-x 2 username username 4096 2019-09-14 12:12 .
drwx------ 12 username username 20480 2019-09-14 11:07 ..
-rw-rw-rw- 1 username username 3027342705 2019-09-14 12:11 lockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$
If the name of the zip turns from red to green in Terminal, remove the x from the permissions line.
Some zipped files are zero bytes as they have not copied or zipped properly. A very big zip archive of too many subfolders may become too hard to handle. Too many files failed to zip here so the archive needs to be remade rather than just refreshed or updated. Delete zip file and directory of zero-size files and run zip again.
Ctrl-alt-t
Up arrow for a command line.
martin@martin-nn37n-aaa:~$ cd /media/160gbSamsung/home/username/.locker/
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ ls
ics9798 pic9024e.zip pics9779 pics9798 vid978 vide1438x zips
id978 pic9024x pics9779e.zip testfold vid986x vidsalv4
To remove a zip archive file:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ rm pics9779e.zip
Do not remove or delete an empty zero directory within a zip archive or all files in the archive will be removed too.
To remove directories, remove rm all their files then remove the directories with rmdir.
To remove or delete a file from within a zip archive, use the -d option.
$ zip -d archivename.zip filename
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ zip -d ide1438e.zip ide1438/video.mp3
deleting: ide1438/video.mp3
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$
The full filename must be typed as it is listed by zip scan files -sf.
To make a new directory:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ mkdir foldtest
To move a folder holding files to be zipped into a new directory:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ mv ics9779/ ./foldtest/ics9779/
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ ls ./foldtest/
ics9779
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$
To remake a zip archive:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ cd ./foldtest/
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ zip -re1T ics9779.zip ics9779/
Enter password:
Verify password:
adding: ics9779/14_988.jpg (deflated 0%)
adding: ics9779/content_k006.jpg (deflated 10%)
adding: ics9779/chanel_fenn_20u874.jpg (deflated 0%)
... adding files to archive ... etc ...
[zik8qPVa] ics9779/ffk10.jpg password:
test of ics9779.zip OK
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ zip -sf ics9779.zip
Scanning list of files in archive ... etc ...
ics9779/2732a574.jpg
ics9779/14o88.jpg
ics9779/tent6.jpg
ics9779/IMG9.jpg
Total 699 entries (240887840 bytes)
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$
To rename a folder, move it mv.
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ ls
ics9779 ics9779.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ mv ics9779 ics9779backup
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ ls
ics9779backup ics9779.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$
To unzip or extract the files from an archive:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ unzip ics9779.zip
Archive: ics9779.zip
creating: ics9779/
[ics9779.zip] ics9779/ffk10.jpg password:
inflating
list of files extracted ... etc ...
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$ ls -als ics9779/
Long list of all files in the extracted directory, with their sizes.
220 -rw-r--r-- 1 username username 221715 2019-07-14 10:37 xnxn13.jpg
272 -rw-r--r-- 1 username username 275308 2019-07-14 10:38 xnxn14.jpg
204 -rw-r--r-- 1 username username 208112 2019-07-14 10:37 xnxn15.jpg
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/foldtest$
This time all the files in the remade archive have a size and none are zero.
To list the files in a zip archive:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ zip -sf lockall.zip | less
Press down arrow to scroll, q to quit.
To unzip or extract the files out of one folder from the archive but not from other folders:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ ls
lockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$ unzip lockall.zip ics9798/*
inflating: ics9798/3_120.jpg
inflating: ics9798/vov13.jpg
inflating: ics9798/y9m03.jpg
inflating: ics9798/ ... etc ...
inflating: ics9798/13_929.jpg
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker/testfold$
To check what files have been zipped:
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ ls testfold
ics9798 lockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ sudo zip -sf lockall.zip
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ sudo zip -sf ./testfold/lockall.zip | less
Archive contains:
ics9779/
ics9779/fk10.jpg
ics9779/18r_560.jpg
ics9779/kgm11.jpg
ics9779/eeiee14.jpg
... etc ...
Press down arrow or page-up key to scroll, letter q to quit.
To mount a second hard drive with the locker archive on it:
To unzip an archive on another disk, change directories cd to the directory containing the zip file then run the unzip command.
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ unzip ./testfold/lockall.zip
inflating files listed ... etc ..
inflating: id978/csw002.wmv
inflating: id978/blb02.mpg
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$
Zip extracted the files into a directory called ics9798.
To check that the files have been zipped properly, unzip them then run List with the -s size option.
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ ls -s testfold/ics9798/
List of filenames and sizes ... etc ...
92 xt010.jpg
368 y99m10.jpg
576 y99m11.jpg
Scroll and see that there are no undersized or zero size files.
To add new files or newly edited files to a zip archive, use the update -u option. Update only adds changed or new files to the archive.
Here one file in an extracted directory was renamed. The recursive -r option is needed.
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$ zip -ur ide1438e.zip ide1438
updating: ide1438/ (stored 0%)
adding: files ... etc ...
ide1438/zzzam.mp3
Total 14 entries (831456411 bytes)
martin@martin-nn37n-aaa:/media/160gbSamsung/home/username/.locker$
The renamed .mp3 file was added to the archive but the original file remained in the archive, two copies of the same file. One copy should be deleted using the -d option as shown above.
To add only freshly edited or changed files to a zip archive, use the freshen -f option.
To mask a zip archive so that the files in it cannot be listed or extracted easily, rename its extension from .zip to something else which must be remembered like a password.
To check the file system on an unmounted partition:
user:~/Desktop$ sudo fsck /dev/sda2
[sudo] password for user:
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
User110gb: clean, 21/3473408 files, 264047/13876709 blocks
user:~/Desktop$
To run a file system check on a hard drive, first unmount the drive.
martin@martin-nn37n-aaa:/media$ fsck
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
/dev/sda1 is mounted.
WARNING!!! The filesystem is mounted. If you continue you ***WILL***
cause ***SEVERE*** filesystem damage.
Do you really want to continue (y/n)? no
check aborted.
martin@martin-nn37n-aaa:/media$
To move an edited or updated zip archive from the hard drive back to a floppy disk, replacing the old archive:
user@user-ID:~/Downloads$ sudo mv sacnu.zip /media/floppy0/
[sudo] password for user:
user@user-ID:~/Downloads$
To remove a zip file or archive:
commandprompt:~/Desktop/testfold$ rm bugteste.zip
To make a new zip file within a directory:
Here a file called locked.zip is made in a directory called ~/.locker/.
user@user-hostname:~$ cd ~/.locker/
user@user-hostname:~/.locker$ ls
pic9024e.zip vide1438original
pic9024b vide1438
user@user-hostname:~/.locker$ zip -re1T locked.zip locked
Enter password:
Verify password:
adding: locked/ (stored 0%)
test of locked.zip OK
user@user-hostname:~/.locker$ ls
vide1438e.zip
locked.zip pic9024e.zip vide1438original
pic9024b vide1438
user@user-hostname:~/.locker$
To zip a directory with all its subdirectories and files, recursively, use the -r option.
zip -r archivename directoryname
To make a directory folder full of files into a zip archive:
The -r recursive option must be used or the new archive.zip will be empty. Here the -e encryption option is used too, to give the new archive a password.
commandprompt:~/Desktop$ zip -re testfolde.zip testfold/
Enter password:
Verify password:
updating: testfold/ (stored 0%)
adding: testfold/sshsh (deflated 40%)
adding: testfold/ccimg.zip (stored 0%)
adding: testfold/fre34e8.jpg (deflated 1%)
adding: testfold/quailprice.png (deflated 2%)
adding: testfold/cciimg.gif (deflated 2%) ... etc
commandprompt:~/Desktop$ zip -sf testfolde.zip
Archive contains:
testfold/
testfold/sshsh
testfold/ccimg.zip
This old zip file which was in the folder went into the zip with the other files.
testfold/ccimg.gif
Total 40 entries (10410862 bytes)
To remove a directory rmdir after it has been made into a zip archive file:
commandprompt:~/Desktop$ ls
2DO testfold
linuxsudob6 testfolde.zip
First remove * all files from the directory.
commandprompt:~/Desktop$ rm ./testfold/*
commandprompt:~/Desktop$ rmdir testfold/
commandprompt:~/Desktop$ ls
2DO testfolde.zip
linuxsudob6 zipsudo
commandprompt:~/Desktop$
To remove directories after they have been added updated into a zip file:
user@user-hostname:~/.locker$ ls
locked.zip pic9024b pic9024extracted vide1438 vide1438original
Be careful not to remove the updated zip file. Remove all the files from the directories.
user@user-hostname:~/.locker$ rm pic9024b/* pic9024extracted/* vide1438/* vide1438original/*
user@user-hostname:~/.locker$ ls
locked.zip pic9024extracted vide1438original
pic9024b vide1438
Remove the empty directories.
user@user-hostname:~/.locker$ rmdir ./*
rmdir: failed to remove './locked.zip': Not a directory
user@user-hostname:~/.locker$ ls
locked.zip
user@user-hostname:~/.locker$
Rmdir has an --ignore option to try.
To automatically move all the files out of the directory and into the new archive, run the command above like this:
zip -re0Tm testdire.zip ./testdir/*
To unzip an archive:
First move the archive into an empty folder, or let it extracct into the current directory.
commandprompt:~/Desktop$ ls
2DO testfold
linuxsudob6 testfolde.zip
Having the folder the same name as the zip makes them easy to manage.
commandprompt:~/Desktop$ mv testfolde.zip ./testfold
commandprompt:~/Desktop$ ls ./testfold
testfolde.zip
Change to the empty local . directory.
commandprompt:~/Desktop$ cd ./testfold
commandprompt:~/Desktop/testfold$ unzip testfolde.zip
Archive: testfolde.zip
creating: testfold/
[testfolde.zip] testfold/sshsh password:
inflating: testfold/sshsh
extracting: testfold/ccimg.zip
inflating: testfold/fre34e8.jpg
inflating: testfold/quailprice.png
... etc
commandprompt:~/Desktop/testfold$
The folder can be deleted because the same files are in the zip.
To fix a zip archive and recover files from it, use the -F option and if that does not fix it, use the -FF option.
zip -F zipfilename --out zipfixed
Recovered files are copied into another directory, in this case one called zipfixed.
To protect a directory by giving it a password without compressing it, use the zero compression option -0 with -re.
Here the directory of files to be zipped is called testdir.
commandprompt:~/Desktop/testfold$ zip -re0 testdire.zip ./testdir/*
Enter password:
Verify password:
adding: testdir/ALEXIS0C71.JPG (stored 0%)
adding: testdir/ap_alexx.jpg (stored 0%)
adding: testdir/banner.jpe (stored 0%)
adding: testdir/bugtest (stored 0%)
adding: testdir/ccimg.zip (stored 0%)
adding: testdir/errors (stored 0%)
adding: testdir/fr12ee5.jpg (stored 0%)
adding: testdir/ipdetect (stored 0%)
adding: testdir/quailprice.png (stored 0%)
adding: testdir/sshsh (stored 0%)
adding: testdir/tibet.mp3 (stored 0%)
commandprompt:~/Desktop/testfold$
Now delete all the files in the directory then remove the directory itself, leaving the zip archive.
commandprompt:~/Desktop/testfold$ rm ./testdir/*
commandprompt:~/Desktop/testfold$ rmdir ./testdir/
commandprompt:~/Desktop/testfold$ ls
testdire.zip testfold testfolde.zip
commandprompt:~/Desktop/testfold$
For security it may be better to have a compression of at least one -1 and a password of at least 9 characters.
To learn more about zip commands, run zip --help
then zip -h2
commandprompt:~/Desktop/testfold$ zip -h2
Extended Help for Zip
See the Zip Manual for more detailed help
Zip stores files in zip archives. The default action is ... etc
-m after archive created, delete original files (move into archive)
-T test archive ... etc
To make a zip file out of a directory which has a zip file in it:
Here the directory to be zipped is called dirtest.
jim@jimGD3:~/Desktop/testfold$ ls
bigzipper.zip testdire.zip testtar
dirtest testfolde.zip
jim@jimGD3:~/Desktop/testfold$ zip -re1Tm dirteste.zip dirtest
Enter password:
Verify password:
adding: dirtest/ (stored 0%)
adding: dirtest/dirtest.zip (stored 0%)
[zibbZ0dN] dirtest/dirtest.zip password:
password incorrect--reenter:
test of dirteste.zip OK
Here the password was typed again when zip tested the new archive.
jim@jimGD3:~/Desktop/testfold$ ls
bigzipper.zip testdire.zip testtar
dirteste.zip testfolde.zip
jim@jimGD3:~/Desktop/testfold$
The directory called dirtest was moved using option -m into the new zip after the new zip was tested -T for its integrity. The right password will be needed to open the files in the -e encrypted zip archive.
zipcloak - To encrypt all the files in a zip file.
username@username-desktop:~$ zipcloak /media/floppy0/vian.ZIP
Enter password:
Verify password:
encrypting: JOIN_MAINPIC.GIF
etc
If you have a usb or floppy drive filled by a zip file, the files in it cannot be encrypted because the drive does not have enough space. Zip files contract but encrypted files expand.
To decrypt the cloaked files, use the -d option.
zipcloak -d /media/floppy0/vian.ZIP
To remove or erase files from a directory:
commandprompt:~$ ls
Backupdesk Downloads newfile.txt Public testdoc
Desktop examples.desktop Pictures Scripts Videos
Documents Music Programs Templates
commandprompt:~$ gedit newfile.txt
commandprompt:~$ rm newfile.txt testdoc
commandprompt:~$
To unzip or open a .zip archive file and extract the files out of it:
Change cd to the directory which has the zip file.
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls
bigzipper dirtest testdire.zip testtar
bigzipper.zip dirteste.zip testfolde.zip
Here the file to be unzipped is called testdire.zip. Run the unzip command like this.
barry@barry-945GCM-S2L:~/Desktop/testfold$ unzip testdire.zip
Archive: testdire.zip
[testdire.zip] testdir/ALEXIS0C71.JPG password:
Enter the password used to make the zip file.
extracting: testdir/ALEXIS0C71.JPG
extracting: testdir/ap_alexx.jpg
extracting: testdir/banner.jpe
extracting: testdir/bugtest
extracting: testdir/quailprice.png
... etc
extracting: testdir/tibet.mp3
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls
bigzipper dirtest testdir testfolde.zip
bigzipper.zip dirteste.zip testdire.zip testtar
See the folder called testdir which was not there before. It holds the unzipped files.
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls ./testdir
ALEXIS0C71.JPG banner.jpe bugtestc errors ipdetect sshsh
ap_alexx.jpg bugtest ccimg.zip fr12ee5.jpg quailprice.png tibet.mp3
barry@barry-945GCM-S2L:~/Desktop/testfold$
Here the practice was to name the zip file after the directory being zipped, with an e added if the zip was encrypted. Unzip remakes the original directory inside the current directory ./ and unzips the files into it.
To unzip zip files within other zip files:
Here in this example, the file to be unzipped is called bigzipper.zip. An empty folder by the same name is in the same folder as the zip.
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls ./bigzipper/
This folder should have been deleted when the zip was made.
barry@barry-945GCM-S2L:~/Desktop/testfold$ unzip bigzipper.zip
Archive: bigzipper.zip
replace dirtest/dirtest.zip? [y]es, [n]o, [A]ll, [N]one, [r]ename: r
new name: testdt
The bizipper.zip archive holds a folder called diretest. This folder too should have been deleted after it was zipped. Here we choose to extract the zip into a new renamed folder.
extracting: testdt
replace testdire.zip? [y]es, [n]o, [A]ll, [N]one, [r]ename: r
new name: testdireb
extracting: testdireb
replace testfolde.zip? [y]es, [n]o, [A]ll, [N]one, [r]ename: r
new name: testfoldeb
extracting: testfoldeb
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls
bigzipper dirtest testdir testdire.zip testfoldeb testtar
bigzipper.zip dirteste.zip testdireb testdt testfolde.zip
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls bigzipper/
barry@barry-945GCM-S2L:~/Desktop/testfold$
There were no files to unzip other than the three zip files which were already in the local directory.
To delete or remove copies of directories and zip archives:
barry@barry-945GCM-S2L:~/Desktop/testfold$ rmdir bigzipper dirtest testdir bigzipper.zip
rmdir: failed to remove `dirtest': Directory not empty
rmdir: failed to remove `testdir': Directory not empty
rmdir: failed to remove `bigzipper.zip': Not a directory
Removes warns that two directories have files in them.
Remove all * files from those two directories then remove the directories themsleves.
barry@barry-945GCM-S2L:~/Desktop/testfold$ rm ./dirtest/* ./testdir/*
barry@barry-945GCM-S2L:~/Desktop/testfold$ rmdir ./dirtest/ ./testdir/
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls
bigzipper.zip testdireb testdt testfolde.zip
dirteste.zip testdire.zip testfoldeb testtar
barry@barry-945GCM-S2L:~/Desktop/testfold$
Remove sees the zip rachive as a file, not a directory.
barry@barry-945GCM-S2L:~/Desktop/testfold$ rm bigzipper.zip
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls
dirteste.zip testdire.zip testfoldeb testtar
testdireb testdt testfolde.zip
barry@barry-945GCM-S2L:~/Desktop/testfold$
Testtar was opened in gedit, saved to the Desktop and removed from the testfold directory.
Those three renamed zip files do not have extensions and cannot be opened without extensions.
To recover a zip file, rename or move it with a .zip extension.
barry@barry-945GCM-S2L:~/Desktop/testfold$ mv testdireb testdireb.zip
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls
dirteste.zip testdireb.zip testdire.zip testdt testfoldeb testfolde.zip
Delete the three copies as they are backed up in the original zips.
barry@barry-945GCM-S2L:~/Desktop/testfold$ rm testdt testfoldeb testdireb.zip
barry@barry-945GCM-S2L:~/Desktop/testfold$ ls
dirteste.zip testdire.zip testfolde.zip
barry@barry-945GCM-S2L:~/Desktop/testfold$
To stop other users from opening a folder by turning it into a zip with a password:
Change to the folder which holds the folder to be zipped.
zip -re1Tm foldername.zip foldername/
To make a locker:
user@user-K66B-HG2:~$ mkdir ~/.locker/locked
The .locker directory can only be seen in file manager if show all files is seleted.
user@user-K66B-HG2:~$ ls ~/.locker/
locked test2tar testtar
There is the locked folder with a couple of old testfiles.
user@user-K66B-HG2:~$ cd ~/.locker
Make the locked folder into a zip file.
user@user-K66B-HG2:~/.locker$ zip -re1Tm locked.zip locked/
Enter password:
Verify password:
adding: locked/ (stored 0%)
test of locked.zip OK
user@user-K66B-HG2:~/.locker$ ls
locked.zip test2tar testtar
user@user-K66B-HG2:~/.locker$
Put two files into the empty locker zip called locked.zip.
user@user-K66B-HG2:~/.locker$ zip -uTm locked.zip test2tar testtar
test of locked.zip OK
user@user-K66B-HG2:~/.locker$ ls
locked.zip
The three options told Zip to -u update the archive by adding the two files to it then -T test the archive and -m remove the old files from the hidden .locker directory.
Scan the zip file -sf to show what is inside it.
user@user-K66B-HG2:~/.locker$ zip -sf locked.zip
Archive contains:
locked/
test2tar
testtar
Total 3 entries (32451 bytes)
user@user-K66B-HG2:~/.locker$
List and grep cannot show the files in locked because it is no longer a directory but a file. To show the files in the locker, run zip with the -sf scan files option. To open some of the files, extract them from the zip. Files can be moved, copied and pasted or downloaded into the locker then added and updated into the locked.zip.
To show the files in a zip archive in another directory:
user@user-K66B-HG2:/$ zip -sf ~/.locker/locked.zip
Archive contains:
locked/
test2tar
testtar
Total 3 entries (32451 bytes)
user@user-K66B-HG2:/$
To list the files in a locked locker, start the command with sudo.
username@username-hostname:/$ sudo zip -sf ~/.locker/locked.zip
Archive contains:
locked/
test2tar
testtar
ghb07.jpg
... etc ...
rvtp_03.jpg
Total 15 entries (1408745 bytes)
username@username-hostname:/$
To unlock a locker:
username@username-hostname:/$ chmod u=rwx ~/.locker
username@username-hostname:/$ ls ~/.locker
bigzipper.zip dirteste.zip hikran.jpg test2tar
... etc
To lock a zip archive so that only a sudo administrator can unlock it:
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ chmod ugo=---------- testinge.zip
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ ls -l
total 24
drwxrwxr-x 2 username username 4096 Aug 24 14:15 jump
drwxrwxr-x 2 username username 4096 Aug 24 14:26 test2
drwxrwxr-x 2 username username 4096 Aug 24 14:26 test3
drwxrwxr-x 2 username username 4096 Aug 24 14:26 testing
---------- 1 username username 5576 Aug 24 14:17 testinge.zip
username@username-id:
The line of hyphens says that nobody can open the zip file.
To unlock a zip archive:
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ sudo chmod u=rwx------ testinge.zip
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ ls -l testinge.zip
-rwx------ 1 username username 5576 Aug 24 14:17 testinge.zip
That means the file - called testingw.zip can now be rwx read, written to or executed by a root user but not by any other user who does not have root privileges. That file is not a program and cannot be executed. So the permissions should not have an x.
To stop users opening a zip file, here is another way of running the chmod command.
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ sudo chmod ugo=---------- testinge.zip
[sudo] password for username:
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ ls -l testinge.zip
---------- 1 username username 5576 Aug 24 14:17 testinge.zip
To add files to a zip file, use the -u update option as shown above.
To unzip a file from a zip archive:
user@user-K66B-HG2:~$ cd ~/.locker/
user@user-K66B-HG2:~/.locker$ unzip locked.zip test2tar
Archive: locked.zip
inflating: test2tar
user@user-K66B-HG2:~/.locker$ ls
locked.zip test2tar
user@user-K66B-HG2:~/.locker$ gedit test2tar
user@user-K66B-HG2:~/.locker$
Gedit opens the text file.
To unzip more files but not all from a zip, use a * wildcard.
unzip locked.zip a*
That opens all files with names beginning with a.
To unzip an archive in a separate directory so that the zipped files do not become mixed with other files:
Make a directory with the same name as the zip file to be extracted. Move the zip archive file into the new directory. Change to the new directory and unzip the archive there. This is a neat way to unzip files because some zip archives extract files without putting them into a subdirectory.
home@user-ID:~$ mkdir ~/Desktop/vian/
home@user-ID:~/Desktop/vian$ mv ~/Desktop/vian.ZIP ~/Desktop/vian/home@user-ID:~/Desktop/vian$ ls ~/Desktop/vian/vian.ZIP
home@user-ID:~/Desktop/vian$ mv ~/Desktop/vian.ZIP ~/Desktop/vian/home@user-ID:~/Desktop/vian$ ls ~/Desktop/vian/vian.ZIP
home@user-ID:~/Desktop/vian$ unzip vian.ZIP
Archive: vian.ZIP
inflating: IMG0038O.JPG
...etc...
inflating: join.jpg
inflating: IMG0058T.JPG
inflating: lftmore.jpg
inflating: LFTPICTURES.JPG
home@user-ID:
To show the hidden locker directory:
$ ls -a ~/
See the directory called .locker in the home directory.
To open a locker, use chmod like a key:
username@username-hostname:~$ cd ~/.locker
bash: cd: /home/username/.locker: Permission denied
username@username-hostname:~$ sudo cd ~/.locker
sudo: cd: command not found
username@username-hostname:~$ chmod u=rwx ~/.locker
username@username-hostname:~$ cd ~/.locker
username@username-hostname:~/.locker$
To lock a locker:
username@username-hostname:~/.locker$ chmod ugo=--------- ~/.locker
Now only sudo can list the files in the locker.
username@username-hostname:~/.locker$ sudo ls ~/.locker
bigzipper.zip dirteste.zip vybp09.jpg
test2tar vp09.jpg chpkan.jpg ... etc testdire.zip locked.zip
username@username-hostname:~/.locker$ ls ~/.lockerls: cannot open directory '/home/username/.locker': Permission denied
username@username-hostname:~/.locker$
To copy files from a usb stick into a hidden directory on the hard drive:
username@username-hostname:/media/username/red8gbusb$ cp *.jpg ~/.locker/
username@username-hostname:/media/username/red8gbusb$ ls ~/.locker
bigzipper.zip hchikan (6).jpg
bp_007.jpg hchikan (9).jpg
bp_008.jpg locked.zip
bp_009.jpg nvbp_009.jpg
bp_012.jpg nvbp_013.jpg
... etc
username@username-hostname:/media/username/red8gbusb$
Image .jpg files have been added to the directory where they can be added to the locked.zip archive file.
To add files to a hidden zip archive:
Here the -u option updates the archive by adding .jpg files to it, -T tests the archive then -m removes the .jpg files from the directory they were in.
username@username-hostname:~/.locker$ zip -uTm locked.zip ./*.jpg
adding: bp_007.jpg (deflated 0%)
adding: bp_008.jpg (deflated 0%)
... etc adding: hchikan (9).jpg (deflated 1%)
adding: nvbp_009.jpg (deflated 0%)
adding: nvbp_013.jpg (deflated 0%)
test of locked.zip OK
username@username-hostname:~/.locker$ ls
bigzipper.zip test2tar testtar
dirteste.zip testdire.zip
locked.zip testfolde.zip
username@username-hostname:~/.locker$ zip -sf locked.zip
Archive contains:
locked/
test2tar
testtar
bp_007.jpg
bp_008.jpg
... etx ...
hchikan (6).jpg
hchikan (9).jpg
nvbp_009.jpg
nvbp_013.jpg
Total 15 entries (1408745 bytes)
username@username-hostname:~/.locker$
Users have permission to scan files in this hidden locker zip. The locked.zip is no longer encrypted because it was updated without the -e option.
To password protect a zip file, update it with the -e option.
username@username-hostname:~$ cd ~/.locker/
username@username-hostname:~/.locker$ ls
bigzipper.zip dirteste.zip nvbp_009.jpg
bp_007.jpg hchikan (11).jpg nvbp_013.jpg
bp_008.jpg hchikan (4).jpg test2tar
bp_009.jpg hchikan (6).jpg testdire.zip
bp_012.jpg hchikan (9).jpg testfolde.zip
bp_019.jpg locked testtar
bp_020.jpg locked.zip
username@username-hostname:~/.locker$ zip -ue locked.zip
Enter password:
Verify password:
updating: testtar (deflated 69%)
username@username-hostname:~/.locker$ unzip locked.zip
Archive: locked.zip
replace test2tar? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
inflating: test2tar
[locked.zip] testtar password:
A user needs the password to open any files in this zip. A user does not need a password to scan and list the files in the zip.
To stop other users from opening the locker directory or seeing what files are in it:
username@username-hostname:~$ cd ~/.locker
username@username-hostname:~/.locker$ ls -ld ./
drwx------ 3 username username 4096 Aug 10 13:51 ./
username@username-hostname:~/.locker$
Only the root owner of this d directory is allowed to r read, w write or x execute files in this directory.
Linux starts its directory tree of files with the root directory. Root is shown on a command line as / a backward slash. The current directory at the command prompt is shown in a command as . a full stop. Other directories or subdirectories in the root directory have a name beginning and ending with a / slash, eg /home/ . File names do not have a slash. Hidden files have names beginning with a . stop. If a command is typed with a space after a slash, eg / home/ , then that command applies to the root directory, not to the home directory. The command $ sudo rm -r / home/Desktop/folder/* means to remove all the files in the root directory and all its subdirectories, not just files in the folder. That is an example of why a space should never be typed in the wrong place on a command line. Two full stops on a command line means the directory before or above the current directory. So two stops or dots must never be typed by mistake when only one is meant.
To unlock the hidden locker directory:
username@username-hostname:~$ chmod ugo=rwx ~/.locker/
username@username-hostname:~$ ls -l ~/.locker/
total 81256
-rw------- 1 username username 40182598 Aug 10 11:56 bigzipper.zip
-rw-r--r-- 1 username username 81486 Aug 10 11:58 bp_007.jpg
-rw-r--r-- 1 username username 153316 Aug 10 11:58 bp_008.jpg
-r ... etc ...
To change the permissios mode of this directory:
username@username-hostname:~/.locker$ chmod ugo=--- ./
username@username-hostname:~/.locker$ ls -ld ./
ls: cannot access './': Permission denied
Now only the root user can open the locker.
username@username-hostname:~/.locker$ sudo ls -ld ./
[sudo] password for username:
d--------- 3 username username 4096 Aug 10 13:51 ./
username@username-hostname:~/.locker$
Even another user who knows the name of a file in the locker cannot open or edit that file.
username@username-hostname:~/.locker$ gedit .*test2tar
Could not open the file “/home/username/.locker/.*test2tar”.
The user does not have permission to open the file called test2tar.
In the change mode command above, ./ means current directory, which is ~/.locker/ . Just . alone also means current directory. Linux allows different ways to write some commands. For example the home directory can be written on the command line as: ~ , ~/ , . or ./ if it is the current working directory, /home, /home/, /home/username or /home/username/ .
To look in a locker directory when it is on a second hard drive
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user$ cd /media/user/c4931570*/home/user/.locker/
Here the long drive name has been shortened with an * asterist.
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user/.locker$ ls
bigzipper.zip locked nvbp_009.jpg test2tar testfolde.zip
dirteste.zip locked.zip nvbp_013.jpg testdire.zip testtar
user@user-hostname:/media/user/c4931570-2671-5w66-9826-8u17827876f/home/user/.locker$
To cd change to a directory on another hard drive in the same computer:
Ubuntu usually mounts a second drive in the /media/ directory.
user@user-id:~$ cd /media/
user@user-id:/media$ ls
floppy floppy0 user
user@user-id:/media$ cd /media/user/
user@user-id:/media/user$ ls
e3740900-7865-4dde-8763-4f03c606898f red8gbusb
user@user-id:/media/user$ cd /media/user/e3740900-7865-4dde-8763-4f03c606898f/
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f$ ls
bin dev initrd.img lost+found opt run srv ubuntu vmlinuz
boot etc lib media proc sbin sys usr
cdrom home lib64 mnt root snap tmp var
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f$ cd /media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Desktop/
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/Desktop$ ls
2DO etc linuxsudo11 gpgsudo sudofloppy
chmoderror.png gpguse nanouse sudogrubhdd
fcrackzip grubconfig sudoshred
user@user-id:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/tomt
To open the files in a zip file on another hard drive, unzip the same as on the main hard drive.
user@user-hostname:/media/user/e3740900-7865-4dde-8763-4f03c606898f/home/user/.locker$ ls
bigzipper.zip locked nvbp_009.jpg test2tar testfold testtar
dirteste.zip locked.zip nvbp_013.jpg testdire.zip testfolde.zip
Here the file called testfolde.zip unzipped into a directory with the same name as the directory which was zipped, testfold. The files in that directory can now be listed and opened by the user who owns them or by the root user.
To regain access to the root directory:
username@username-hostname:~$ ls -l /
ls: cannot open directory '/': Permission denied
username@username-hostname:~$ chmod ugo=rwx /
chmod: changing permissions of '/': Operation not permitted
username@username-hostname:~$ sudo chmod ugo=rwx /
[sudo] password for username:
username@username-hostname:~$ ls -l /
total 104
drwxr-xr-x 2 root root 4096 Dec 19 2018 bin
drwxr-xr-x 3 root root 4096 Dec 19 2018 boot
drwxrwxr-x 2 root root 4096 Dec 19 2018 cdrom
drwxr-xr-x 20 root root 4600 Aug 16 15:53 dev
etc ...
rwxr-xr-x 11 root root 4096 Feb 16 2017 usr
drwxr-xr-x 14 root root 4096 Feb 16 2017 var
lrwxrwxrwx 1 root root 29 Dec 19 2018 vmlinuz -> boot/vmlinuz-4.8.0-36-generic
username@username etc
Access to the root directory is restored although by default, users in groups and other users are not allowed to write to this directory.
For security, an operating system usually has only one root user, the one who installed it.
To show the name of a usb device and where it is mounted, first list the /mnt or /media directory.
user@user-K66B-HG2:~$ ls /media/
cddvd floppy floppy0 hdd usb user
user@user-K66B-HG2:~$ ls /media/usb/
It is not here.
user@user-K66B-HG2:~$ ls /media/user/
red8gbusb
user@user-K66B-HG2:~$
It is called red8gusb and it is mounted at /media/user
To find the system name and mount point of a device:
Here the device is a usb stick.
Parted lists drive partitions.
user@user-K66B-HG2:~$ sudo parted -l
Model: ATA SanDisk SP12 (scsi)
Disk /dev/sda: 126GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 124GB 124GB primary ext4 boot
5 32.0GB 40.0GB 8003MB logical fat32
Scroll down the page until you see USB DISK.
Model: USB DISK 2.0 (scsi)
Disk /dev/sde: 8011MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
This usb device partition is mounted at /dev/sde.
Or pipe parted output to grep.
user@user-K66B-HG2:~$ sudo parted -l | grep /dev/
Here Grep prints to screen only lines with /dev/ in them.
Disk /dev/sda: 126GB
Disk /dev/sdb: 320GB
Disk /dev/sdc: 40.0GB
Disk /dev/sdd: 40.0GB
Disk /dev/sde: 8011MB
Or run the df command which shows the free disk space on mounted partitions.
user@user-K66B-HG2:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 6.5M 389M 2% /run
/dev/sda1 114G 7.8G 100G 8% /
tmpfs 2.0G 256K 2.0G 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 395M 68K 395M 1% /run/user/1000
/dev/sde1 7.5G 5.3G 2.2G 71% /media/user/red8gbusb
user@user-K66B-HG2:~$
There is the usb stick red8gbusb, device name sde1, an 8gb drive mounted at ?media/user.
Or run Fdisk partitioner.
user@user-K66B-HG2:~$ sudo fdisk -l | tail
The -l option tells Fdisk to list all the drive partitions. Piping this fdisk command to Tail prints only the last 10 lines to screen, assuming the usb is listed last.
Disk /dev/sde: 7.5 GiB, 8011120640 bytes, 15646720 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00046edc
Device Boot Start End Sectors Size Id Type
/dev/sde1 62 15635593 15635532 7.5G 83 Linux
user@user-K66B-HG2:~$
eject - The eject command was for CD and DVD disks and might not work safely with USB sticks and removable drives on old operating systems.
To safely remove or eject a USB drive or memory stick from the computer system, first find its device name.
user@user-K66B-HG2:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
... etc
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 395M 68K 395M 1% /run/user/1000
/dev/sde1 7.5G 5.3G 2.2G 71% /media/user/red8gbusb
user@user-K66B-HG2:~$
There is the usb stick red8gbusb, device name sde1, an 8gb drive mounted at /media/user.
umount - The umount command was for unmounting hard drives and other drives.
user@user-K66B-HG2:~$ ls /media/user/red8gbusb
user@user-K66B-HG2:~$ umount /dev/sde1
user@user-K66B-HG2:~$ ls /media/user/
user@user-K66B-HG2:~$
There is nothing at the mount point. You can safely remove the usb stick from the computer.
Note the sde1 is the drive whereas sde is the partition on the drive. Umount the drive itself.
When Umount unmounts a USB stick, Devices manager shows that the usb has been unmounted but in Ubuntu Nautilus files manager still shows the usb stick. Right click the usb icon and select eject to update Nautilus.
To check that a usb stick has been unmounted, run the free disk command:
user@user-K66B-HG2:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 6.5M 389M 2% /run
/dev/sda1 114G 7.8G 100G 8% /
tmpfs 2.0G 256K 2.0G 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 395M 68K 395M 1% /run/user/1000
user@user-K66B-HG2:~$
There is no usb device, only a 114gb hard drive.
To show the device name and mount point of a floppy drive:
username@username-hostname:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 6.5M 389M 2% /run
/dev/sda1 114G 7.9G 100G 8% /
etc ... dev/sdb1 288G 193G 81G 71% /media/username/185ce059-d153-44dc-9eb9-d4737f5c0692
/dev/sdc1 35G 4.7G 29G 15% /media/username/d60b90e4-2d06-476b-95fa-517c25f1d62f
/dev/sdd1 30G 17G 14G 57% /media/username/2D71-12ED
/dev/fd0 1.4M 0 1.4M 0% /media/floppy0
username@username-hostname:~$
The floppy is /fd0 and it is mounted at /media/floppy0 .
To set permissions for files and folders:
The root user, that is the superuser, and any user who owns a file or directory can usually change the permissions of that file or directory so that other users may or may not be allowed to read, write or execute the file or directory. Most users give themselves read, write and execute permissions but deny all permissions to other users in their group or to any other users at all.
To change the mode chmod of a file to allow the user u who owns a file, members of his group g of users and other o users to read r, write to w and execute x that file:
chmod ugo=rwx filename
user@user-abc-123:~$ chmod ugo=rwx ~/Desktop/floppyt
user@user-abc-123:~$
That command changes the mode of a file called floppyt in the Desktop directory.
To stop users in the group and other users from reading, writing to or executing a file:
user@user-abc-123:~$ chmod go=--- ~/Desktop/floppyt
Now only the user who owns the file can read, write to or run it.
To show the permissions of a file, run list with the long list option -l.
user@user-abc-123:~$ ls -l ~/Desktop/floppyt
-rwx------ 1 username username 1002 2019-08-05 14:06 /home/username/Desktop/floppyt
user@user-abc-123:~$
The first - means an ordinary file.
A d means a directory.
touch - To open a new, empty file:
user@user-abc-123:~$ touch ~/Desktop/testnote
user@user-abc-123:~$ ls ~/Desktop/testnote
/home/username/Desktop/testnote
user@user-abc-123:~$
To show the default permissions for a new file:
user@user-abc-123:~$ ls -l ~/Desktop/testnote
-rw-r--r-- 1 username username 0 2019-08-12 15:27 /home/username/Desktop/testnote
user@user-abc-123:~$
The owner can read or write to it and members of his user group and other users can only read it. Nobody can x execute it because it is not an executable file.
umask - To check the default permissions for files in a system:
user@user-abc-123:~$ umask
0022
user@user-abc-123:~$
By default most Linux distros set umask to 0022 (022) or 0002 (002).
To change the default permissions for all files from now on:
$ umask u=rwx,g=,o=
Umask set to u=rwx,g=,o= gives new files -rw—— permissions, and new directories drwx—— permissions.
To show the permissions of a directory, use the ls command with option -l for a long list and option d for directory.
user@user-abc-123:~$ ls -ld ~/Desktop/directest/
drwxr-xr-x 2 username username 4096 2019-08-12 15:40 /home/username/Desktop/directest/
user@user-abc-123:~$
A user who does not have permission to access a directory is still able to read a file in that directory if he knows the name of that file and has permission to read that type of file.
To change the permissions of a directory:
For directories, r lets you read what is in the directory, w lets you create files and subdirectories within the directory, and x lets you enter a directory.
user@user-abc-123:~/Desktop/directest$ ls -ld ./
drwxrwxrwx 2 username username 4096 2019-08-12 15:40 ./
To stop other users from accessing this directory:
user@user-abc-123:~/Desktop/directest$ chmod go=--- ./
user@user-abc-123:~/Desktop/directest$ ls -ld ./
drwx------ 2 username username 4096 2019-08-12 15:40 ./
user@user-abc-123:~/Desktop/directest$
To change the mode of a directory so that only the user can access it, read, write or execute the files in it:
Here the permissions of a hidden folder called .locker are being changed.
cathy@cathy-hostname:~$ sudo chmod -R u=rwx,g=---,o=--- ~/.locker
cathy@cathy-hostname:~$ ls -l ~/.lockertotal 80332
-rwx------ 1 cathy cathy 40182598 Aug 10 11:56 bigzipper.zip
-rwx------ 1 cathy cathy 20501878 Aug 10 11:56 dirteste.zip
-rwx------ 1 cathy cathy 82222 Aug 10 11:58 hchikan (4).jpg
drwx------ 2 cathy cathy 4096 Aug 9 09:51 locked
-rwx------ 1 cathy cathy 1386060 Aug 10 13:45 locked.zip
-rwx------ 1 cathy cathy 184240 Aug 10 11:58 nvbp_009.jpg
-rwx------ 1 cathy cathy 184816 Aug 10 11:58 nvbp_013.jpg
-rwx------ 1 cathy cathy 16184 Aug 6 18:15 test2tar
-rwx------ 1 cathy cathy 9427819 Aug 10 11:56 testdire.zip
-rwx------ 1 cathy cathy 10252623 Aug 10 11:56 testfolde.zip
-rwx------ 1 cathy cathy 16267 Aug 4 15:39 testtar
cathy@cathy-hostname:~$
To update the Grub bootloader after installing a dual operating system:
cathy@cathy-hostname:~$ sudo update-grub
[sudo] password for cathy:
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.8.0-36-generic
Found initrd image: /boot/initrd.img-4.8.0-36-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Ubuntu 16.04.2 LTS (16.04) on /dev/sda3
done
cathy@cathy-hostname:~$
Or run sudo update-grub2 for Grub version 2.
Restart the computer to show the grub dual-boot menu.
To edit grub commands if need be:
Restart the computer and hold down the shift key to see grub advanced options.
nano - If you see errors when you are editing Grub files with Gedit, use Nano editor instead. This is because Nano works from within Terminal whereas Gedit works separate as a graphic program.
To start Nano and open a new text file:
in Terminal run the nano command, $ nano /directoryname/filename. That is the name of the directory where the new file is to be made. Start typing.
To open and edit an existing file, run nano as above but with the existing directory and filename.
To edit system files, use a sudo command and type the root password.
To get help and learn about Nano, ctrl-g, press arrow keys to scroll commands.
To close the help menu, ctrl-x.
To search for a key word within a text file, ctrl-w, type the word and press enter, cursor goes to the word in the text.
To cut a word out of the text, use arrow keys to move cursor to the word then use the backspace key to delete it.
To cut or delete a line, put the cursor on it and press ctrl-k.
To uncut text, ctrl-u.
To break a line, Enter.
To justify the text, ctrl-j.
To unjustify the text, ctrl-u-j.
To open a Terminal window, right click anywhere and select
open terminal.
To move cursor, press arrow keys, pageup or pagedown.
To insert another file into the current one, ctrl-r.
To go back to previous screen, ctrl-x.
To save or write the current edited text file to disk, ctrl-o, ctrl-t, ctrl-x.
To save the current text file and exit nano, ctrl-x, type y for yes, check that the directory and filename are right on the prompt line, press enter.
To cancel a promptline, ctrl-c.
To exit Nano, ctrl-x.
To see the Grub boot menu, restart the computer and hold down the shift tkey.
To edit a system file:
Here the file is called grub.
user@user-hostname:~$ sudo nano /etc/default/grub
The file opens in Nano where it can be edited as shown above.
To tell Grub bootloader to boot a different partition on a hard drive at startup:
Here the grub file was edited on the hard drive partition which had usually been automatically booted as the 0 first choice. The editor user typed a # comment to say what he had changed. The different hard drive part to be booted was listed on the 4th line down in the Grub boot menu. So the editor changed 0 to 4.
user@user-hostname:~$ sudo nano /etc/default/grub
[sudo] password for user:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
# User changed default 0 to 4.
GRUB_DEFAULT=4
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
etc ...
The editor user typed a # comment to say what he has changed.
To update the grub boot configuration after editing:
user@user-hostname:~$ sudo update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.8.0-36-generic
Found initrd image: /boot/initrd.img-4.8.0-36-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Ubuntu 16.04.2 LTS (16.04) on /dev/sda3
...etc ...
user@user-hostname:~$ sudo grub-mkconfig
Generating grub configuration file ...
# DO NOT EDIT THIS FILE
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
etc ... elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
done
user@user-hostname:~$
To password protect a directory, change it into an archive file:
tar czf filename.tar.gz directoryname/
Here a hidden directory called .locker is made into a tar file with the same name. The options czf say to change a directory into an archive.gz file.
.data .locker sb21819.odt
directest .~lock.heartsong.odt# sb21819.png
bert@bert-945GCM-S2L:~$ tar czf ~/Desktop/.locker.tar.gz ~/Desktop/.locker/
tar: Removing leading `/' from member names
bert@bert-945GCM-S2L:~$ ls -a ~/Desktop/
. gpartedhow salvagehow
.. gpgfolder .sb12916ps
2do gpgfolder.png sb21819.odt
.cache grubstart swappartition
cbank81214.pdf .locker taropenssl
cleansys .locker.tar.gz
There is the .locker directory and the new tar archive.
To turn a tarball file back into a directory:
tar xzf filename.tar.gz
gpg - To make a private key with which to encrypt and password protect files:
gpg --gen-key
bert@bert-945GCM-S2L:~$ gpg --gen-key
gpg (GnuPG) 1.4.10; Copyright ...et ...
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
= key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter) "
Real name: bert
Email address: bertb@duesseldorf.de
Comment: key
You selected this USER-ID:
"bert (key) "
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
You need a Passphrase to protect your secret key.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
+++++........+++++
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
(Need 92 more bytes)
detgjukidjrn h dnjfuhdsn5768nchdg32546bshfu87364kjnd nsj kiaqbnzkaopdlfjghuwieopqqlakkmznxhdsbr..+++++
gpg: key 5CE76B49 marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 3 signed: 2 trust: 0-, 0q, 0n, 0m, 0f, 3u
gpg: depth: 1 valid: 2 signed: 0 trust: 0-, 0q, 0n, 1m, 1f, 0u
pub 2048R/5CE76B49 2019-08-22
Key fingerprint = F139 36B2 B1F8 42CE 13AC 85E4 7FA8 DAC6 5CE7 6B49
uid bert (key)
sub 2048R/D9088644 2019-08-22
bert@bert-945GCM-S2L:~$
Note the user ID line, public and private keynumbers and passphrase.
To encrypt a file:
bert@bert-945GCM-S2L:~$ gpg -e -r bert ~/Desktop/.locker.tar.gz
bert@bert-945GCM-S2L:~$ ls -a ~/Desktop
. gpartedhow .rsrc
.. gpgfolder
cbank81214.pdf .locker swappartition
cleansys .locker.tar.gz taropenssl
compulog719.odt .locker.tar.gz.gpg testfold
etc ...
bert@bert-945GCM-S2L:~$
The encrypted file is the one listed with a .gpg ending.
Files manager and Archive manager cannot open the .gpg file until it is decrypted.
To decrypt the file, type
gpg -d -o bert/decrypted ~/Desktop/.locker.tar.gz
which will create the new file decrypted.
bert@bert-945GCM-S2L:~$ gpg -d -o ~bert/decrypted ~/Desktop/.locker.tar.gz.gpg
You need a passphrase to unlock the secret key for
user: "bert (key) "
2048-bit RSA key, ID D9088644, created 2019-08-22 (main key ID 5CE76B49)
gpg: encrypted with 2048-bit RSA key, ID D9088644, created 2019-08-22
"bert (key) "
bert@bert-945GCM-S2L:~$
bert@bert-945GCM-S2L:~$ ls -a ~/Desktop/
. gpgfolder .rsrc
gpgfolder.png salvagehow
grubstart sb21819.png
cbank81214.pdf home swappartition
cleansys .locker taropenssl
compulog719.odt .locker.tar.gz testfold
.config .locker.tar.gz.gpg testhome
The file called .locker.tar can now be extracted into a folder called .locker. The same filename can be kept to avoid confusion and loss of files. In the example above, the original folder and its tar file were not deleted or removed. For security, the original folder and tar file should be removed.
To list details about a gpg encryption key:
gpg --list-keys
bert@bert-945GCM-S2L:~$ gpg --list-keys
/home/bert/.gnupg/pubring.gpg
------------------------------
pub 2048R/6YGT4O93 2019-08-22
uid bert (key)
sub 2048R/D9088644 2019-08-22
bert@bert-945GCM-S2L:~$
Note the pub key ID, the characters after the forward stroke. Here the id is 6YGT4O93.
To edit the key:
gpg --edit key idnumber
bert@bert-945GCM-S2L:~$ gpg --edit key 6YGT4O93
gpg (GnuPG) etc ...
Secret key is available.
pub 2048R/35154AD3 created: 2016-11-07 expires: never usage: SC
trust: ultimate validity: ultimate
sub 2048R/U8IURWM2 created: 2016-11-07 expires: never usage: E
[ultimate] (1). Bert B (encryption key)
No user ID with index 5
Command>
To see gpg commands, type help.
To change the password, type passwd
In the popup field, type the old password.
Type a new pasword, and again.
Command> passwd
Key is protected.
You need a passphrase to unlock the secret key for
user: "bert (key) "
2048-bit RSA key, ID 6YGT4O93, created 2019-08-22
Enter the new passphrase for this secret key.
Command>
Save the new password with this command -
Command> save
bert@bert-945GCM-S2L:~$
Remember that password. That password is for decrypting or digitally signing documents, text files.
To run the operating system and programs on one partition of a hard drive but work with the user files on another partition, keep note of the path to the desktop on the user partition and copy and paste it into a cd change directory command.
username@username-id:/$ cd /media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop$
To find the pathway to a directory on another partition, change directory cd to /media/username/, list the subdirectories, keep changing until the destination directory is reached then copy the path to it and paste it into a text file for use whenever. Some Linux systems mount a separate hard drive in /mnt/ directory or some other directory instead of /media/.
To open a file which only sudo can open, run a sudo command:
606898f/home/username/Desktop/.testfold$ unzip testinge.zip
error: cannot open zipfile [ testinge.zip ]
Permission denied
unzip: cannot find or open testinge.zip, testinge.zip.zip or testinge.zip.ZIP.
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ ls -l testinge.zip
---------- 1 username username 5576 Aug 24 14:17 testinge.zip
List shows that the file is e encrypted with a password and its permissions are ugo=----------.
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$ sudo unzip testinge.zip
[sudo] password for username:
Archive: testinge.zip
... etc ...
replace testing/fcrackzip? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
inflating: testing/fcrackzip
username@username-id:/media/username/e3740900-7865-4dde-8763-4f03c606898f/home/username/Desktop/.testfold$
-dd Data Duplicator, see ddsudo.txt, ddrescue.txt, dduplicator.txt. The dd command copies disks. DD can make an .iso image of a CDisk or copy the data of one hard drive to another hard drive, for example. Data Duplicator DD is a disk imaging program for Linux and it is installed with Ubuntu. see also dduplicator.txt, ddrescue.txt
-dd
To recover files from a floppy disk:
Ctrl-alt-t to start Terminal.
Type the command mount devicename mountpoint to mount the floppy disk, something like
mount /dev/disk1 on /media/username
where disk1 is the floppy disk.
Then unmount the floppy with
sudo umount -f /mountpoint
like sudo umount -f /media/username
Remove the floppy and write protect it by sliding its square hole open, so both holes are open.
In the following dd command, if means input file and of means output file. Be careful not to mix them up by mistake.
dd if=/dev/disk1=~Desktop/imagefilename.dmg
That command copies or streams all file data from the floppy into the imagefile on the desktop. Call the image file what you will.
Wait until DD shows a message that it has finished copying, or failed.
Double click the imagefile on the desktop to launch it.
With Linux, try naming the imagefile with an extension .img instead of .dmg.
-rename To rename files, use the rename command with a substitute expression. The command has three options. Option -n says no action so that Rename will only show in a test run the files to be renamed. Other options may be -v for verbose to show what files have been renamed, and -f for force to overwrite existing files or the original file. The s for substitute begins a regular expression. Any such expression must be enclosed in single quotes and its parts separated by forward slashes /. Rename can use wildcards like the asterisk *. A letter g can be added to the end of an expression just before the closing quote to tell Rename to substitute for every mention of the word to be replaced. A regular expression is called perlexpr because it is written in Perl programming language.
To rename only a few files, it is easier to run remove rm instead of rename.
To rename many files or types of files, run rename.
To rename any files with the extension .jpeg to have the extension .jpg.
rename 's/\.jpeg$/.jpg/' *
To rename all .jpg files as .pdf files:
user@user-12ri:/media/160gbSamsung/home/username/.locker/testfold/ics9798$ rename 's/\.jpg$/.pdf/' *
A backslash and a $ were were needed in that command which changed all .jpg extensions to .pdf. The backslash and $ are Perl metacharacters. The slash means the characters following are not metacharacters. The $ means to match the end of a string of characters. The last part of the command, after the expression, * in the command above and *.bak in the command below, tells Rename which file or type of file to rename. Even though a .jpg file is renamed with a .pdf extension, it will still open as an image when its icon is clicked in filemanager.
To rename pdf files back to their original jpg extensions:
user@user-12ri:/media/160gbSamsung/home/username/.locker/foldtest/ics9779$ rename 's/\.pdf$/.jpg/' *
To rename all files ending with *.bak so that they no longer show any extension:
rename 's/\.bak$//' *.bak
That command tells Rename to find .bak and replace it with nothing. Do not remove the extensions because they may be hard to restore.
user@user-12ri:/media/160gbSamsung/home/username/.locker/testfold/ics9798$ rename 's/\.pdf$//' *.pdf
That command removed the . extension from all filenames ending with .pdf, in the current directory. Even without any extension showing, the files will automatically open when clicked in file manager.
To mask all the .jpg files in a folder from view, rename them with .rtf extensions. When hiding files this way, the change of extension must be remembered like a password.
To mask all .mp4 files from view, rename them with .doc extensions.
By default, the rename command will not overwrite existing files. Use the -f argument to allow existing files to be over-written.
rename -f 's/.html/.php/' *.html
To rename a file back with its extension, the -f force option may be needed to overwrite the old file.
user@user-12ri:/media/160gbSamsung/home/username/.locker/testfold/ics9798$ rename -f 's/znzzm07*/znzzm07.jpg/' znzm07*
List shows the one file with its .jpg extension, znnz9
nzzm07.jpg
nzzm08 ... etc ...
The -f was not needed here.
To quit Rename if a command stalls, press ctrl-\ , control backlash keys.
To help avoid typing errors in commands: use the up arrow key to reuse successful commands typed earlier, copy and paste commands, always click the cursor on the command line and watch that the cursor is flashing before typing or pasting a command, and read the command before pressing enter to run it.
chattr - To change the attributes on a file or directory so that it cannot be edited or deleted, run chattr.
trevor@trevor-ID:~$ chattr
Usage: chattr [-RVf] [-+=aAcCdDeijsStTu] [-v version] files...
trevor@trevor-ID:~$
see chattrhow.txt
To encrypt a file with gpg and overwrite an old file:
The file here is called testroll. A -c option tells Gpg to use a symmetric key instead of a cipher.
user@user-ID:~/Desktop$ gpg -c testroll
File `testroll.gpg' exists. Overwrite? (y/N) y
user@user-ID:~/Desktop$ ls
allianz19.png
... etc ...
sudolock
testroll
testroll.gpg
vgough-encfs-ce200c8
vgough-encfs-v1.9.5-9-gce200c8.tar.gz
vgough-encfs-v1.9.5-9-gce200c8.zip
user@user-ID:~/Desktop$ ls testroll.gpg
To decrypt a gpg file and open it:
user@user-ID:~/Desktop$ gpg -d testroll.gpg
gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
File Roller Archive Manager
File Roller opens zip archive files and extracts files out of the archives. ... etc ...
gpg: warning: message was not integrity protected
user@user-ID:~/Desktop$
To make a more secure locker, run these commands:
user@user-ID:~$ mkdir .locker
user@user-ID:~$ ls -a
. Music
... etc ..
.local .wvdial.conf
.locker .xine
.macromedia .xinput.d
... etc ...
user@user-ID:~$
user@user-ID:~$ sudo chmod u=rwx,g=---,o=--- .locker/
[sudo] password for trevor:
user@user-ID:~$ ls -al .locker/
total 8
drwx------ 2 trevor trevor 4096 2019-09-26 09:30 .
drwx------ 71 trevor trevor 4096 2019-09-26 09:40 ..
user@user-ID:~$
user@user-ID:~$ cd .locker/
user@user-ID:~/.locker$
user@user-ID:~/.locker$ mkdir archive1/
user@user-ID:~/.locker$ mkdir archive1/archive1/
user@user-ID:~/.locker$ ls archive1/
archive1
user@user-ID:~/.locker$
Copy cp files into the second archive directory.
user@user-ID:~/.locker$ ls archive1/archive1/
wiring wiring220px.jpg wiring-Out.jpg
wiring09.JPG wiring5812.jpg
user@user-ID:~/.locker$
user@user-ID:~/.locker$ zip -re1Tm archive1.zip archive1
Enter password:
Verify password:
adding: archive1/ (stored 0%)
adding: archive1/archive1/ (stored 0%)
adding: archive1/archive1/wiring09.JPG (deflated 1%)
adding: archive1/archive1/wiring-Out.jpg (deflated 4%)
adding: archive1/archive1/wiring5812.jpg (deflated 0%)
adding: archive1/archive1/wiring220px.jpg (deflated 2%)
adding: archive1/archive1/wiring (deflated 62%)
[ziOGUU7Y] archive1/archive1/wiring09.JPG password:
test of archive1.zip OK
user@user-ID:~/.locker$
user@user-ID:~/.locker$ mv archive1.zip archive1.tar
Those commands made a more secure hidden locker directory with restricted access and hidden files that are protected with passwords. See lockeruse.txt.
To show the user permissions of the locker directory:
Here the locker is in the root user's directory on a second hard drive.
user@user-ID:~$ cd /media/160gbSamsung/home/trevor/
user@user-ID:/media/160gbSamsung/home/trevor$ ls -al
total 308 etc ...
dr-------- 13 trevor trevor 20480 2019-09-19 08:07 .locker
drwx------ 3 trevor trevor 4096 2013-07-23 15:41 .mission-control
drwx------ 4 trevor trevor 4096 2013-07-23 14:11 .mozilla
The sudo user has permission to read only.
To lock the locker:
user@user-ID:/media/160gbSamsung/home/trevor$ chmod ugo=--------- .locker/
user@user-ID:/media/160gbSamsung/home/trevor$ ls -altotal 308 etc ...
drwxr-xr-x 3 trevor trevor 4096 2013-07-23 14:01 .local
d--------- 13 trevor trevor 20480 2019-09-19 08:07 .locker
drwx------ 3 trevor trevor 4096 2013-07-23 15:41 .mission-control
Now no user has any permissiion to access the locker.
To unlock the locker:
user@user-ID:/media/160gbSamsung/home/trevor$ chmod u=rwx------ .locker/
user@user-ID:/media/160gbSamsung/home/trevor$ ls -al
total 308
drwx------ 13 trevor trevor 20480 2019-09-19 08:07 .locker
drwx------ 3 trevor trevor 4096 2013-07-23 15:41 .mission-control
Now only the root user can read and write to the locker directory.
To hide the locker: in file manager, deselect show hidden files. The locker names starts with a dot to hide it.
To show the locker: in file manager, select show hidden files.
To access all directories and files with file manager: click places, computer, copy the computer icon to the desktop as a link.
To list what is in the locker:
First unlock it.
user@user-ID:/media/160gbSamsung/home/trevor$ ls .locker/
foldtest id978 ... etc zips
icr1.xyz id986 ics9798 ide1438e.xyz
To check the locker:
user@user-ID:/media/160gbSamsung/home/trevor$ cd .locker/
bash: cd: .locker/: Permission denied
Or user@user-ID:/media/160gbSamsung/home/trevor$ cd /media/160gbSamsung/home/trevor/.locker/
bash: cd: /media/160gbSamsung/home/trevor/.locker/: Permission denied
The locker is locked.
To open the locker:
First unlock and change to the locker directory.
user@user-ID:/media/160gbSamsung/home/trevor$ cd .locker/
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
foldtest id978 etc ... icr1.xyz id986 ics9798 ide1438.xyz
Root user can now access the files in the locker.
To tidy the locker:
The only files in the locker should be ssl encrypted files, zip encrypted files and one or two directories currently being worked on. Other directories should be zipped as files. Remove unzipped directories which are copies of zips. Both ssl and zip encrypted files are password protected. Directories should be zipped with the -m option to remove the original directory and its files. Zip files have the same names as the directories they replace.
To remove a directory from the locker, list it and make sure there are no zip files in it, remove the files in it then remove the directory:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ rm p*/*
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ rmdir p*/
Those two commands removed all directories with names starting with p.
File recovery programs can recover many zip files even after they have been removed or deleted but the zips still cannot be opened without a password. Password hacking programs can open most zip files.
To zip a directory in the locker:
Unlock the locker.
Move or cut and paste the directory into the locker.
user@user-ID:~$ cd /media/160gbSamsung/home/trevor/.locker/
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
icr1.xyz ics9779.zip id978 karate
ics9779 ics9798 ide1438.xyz
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
The directory to be zipped here is called karate.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -re1Tm karate.zip karate/
Enter password:
Verify password:
adding: karate/ (stored 0%)
adding: karate/japa.PDF (deflated 3%)
adding: karate/japkarate (deflated 33%)
adding: karate/japa1.BMP (deflated 44%)
[zifs2cIX] karate/japa.PDF password:
test of karate.zip OK
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
To mask a zip archive file, rename it with a different extension. That extension should be the same for all masked zips and should be remembered like a password. Choose an extension that will stop the file from opening.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ mv karate.zip karate.xyz
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ics9779.zip id978 karate.xyz ics9779 ics9798 ide1438.xyz
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
To mask the locker, rename it something that makes it look like something other than what it is. Remember the new name like a password.
To unzip a zip file:
Rename it with the .zip extension.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ mv karate.xyz karate.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ unzip karate.zip
Archive: karate.zip
creating: karate/
[karate.zip] karate/japa.PDF password:
inflating: karate/japa.PDF
inflating: karate/japkarate
inflating: karate/japa1.BMP
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ lsicr1.xml ics9779.zip id978 karate
ics9779 ics9798 ide1438.xml karate.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
Zip automatically removed the original karate folder and unzip restored it. The original folder should be removed again after use because it is already in a zip archive.
Mask the zip again.
To list what files are in a zip archive:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -sf karate.zip
or zip -sf karate.xyz
Archive contains:
karate/
karate/japa.PDF
karate/japkarate
karate/japa1.BMP
Total 7 entries (26490383 bytes)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
Zip scans and lists the files even if the extension of the archive has been changed. Bash list command cannot list the files in a zip.
To rename all .zip files in the locker as .xyz files:
rename 's/\.zip$/.xyz/' *
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
id978 locked3.zip newdire.zip
ics9779.zip id986.xml lockall.zip locked.zip
ics9798 locked2.zip newdire2.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ rename 's/\.zip$/.xyz/' *
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
id978 locked3.xyz newdire.xyz
ics9779.xyz lockall.xyz locked.xyz
ics9798 ide1438.xml locked2.xyz newdire2.xyz
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
To rename .xyz files back to their original .zip extensions:
user@user-ID:/media/160gbSamsung/home/trevor/.locker/foldtest/ics9779$ rename 's/\.xyz$/.zip/' *
To store files in the locker:
All files are collected into directories. Directories are moved into the locker. There they are zipped as archives one at a time. Archives are named the same as the directories zipped. Then Zip extensions are renamed. All zips are renamed with the same extension.
To store single files:
Single files are encrypted with Openssl and kept in relevant directories other than the zip.
To update a zip archive by adding directories and files to it:
Here the archive happens to be called append.zip and two directories are added to it.
$ zip -u -r append.zip ics9798 id978
The -r recursive option must be typed separate from the -u update option for Zip.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -u -r append.zip ics9798 id978
The -u option is for updating and the unzip command is for extracting.
To check that an archive has been updated:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -sf append.zi
List of all the update files.
id978/lyyl04.wmv
id978/csw02.wmv
id978/blb02.mpg
... etc ...
Total 17 entries (3052706093 bytes)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
Without the recursive -r option in the command, Zip would add the folders empty.
/trevor/.locker$ zip -sf append.zip ics9798/
Would Add/Update:
ics9798/
Total 1 entries (0 bytes)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
The directory in the zip is empty.
This next command would tell Zip to extract all the files out of the two directories and add them into the archive, but without the two directories.
zip -u append.zip ics9798/* id978/*
To unzip one of a few directories in an archive:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ unzip append.zip ics9798/*
List of files extracted.
inflating: ics9798/k120.jpg
inflating: ics9798/vov3.jpg
inflating: ics9798/y9m3.jpg
... etc ...
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
To list the extracted files:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls ics9798
List shows all the files in the extracted directory called ics9798.
To make a safe file:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ gedit safe
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -re1T safe.zip safe
Enter password:
Verify password:
adding: safe (deflated 40%)
[zitsfOC0] safe password:
test of safe.zip OK
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -re1T safee.zip safe.zip
Enter password:
Verify password:
adding: safe.zip (stored 0%)
[ziWyL4Ci] safe.zip password:
test of safee.zip OK
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
safee.zip safe.zip safe safee
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -ur safee.zip safe
adding: safe (deflated 50%)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -sf safee.zip
Archive contains:
safe.zip
safe
Total 2 entries (767 bytes)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ unzip safee.zip
Archive: safee.zip
[safee.zip] safe.zip password:
replace safe.zip? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
extracting: safe.zip
replace safe? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: safe
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ gedit safe
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ gedit safee
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
To add text to or edit the safe file:
Extract the first zip file then the zip file inside it. Then open the safe file with Gedit and edit it.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -ur safe.zip safefile
adding: safefile (deflated 71%)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -sf safe.zipArchive contains:
safe
safefile
Total 2 entries (1929 bytes)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ unzip safe.zipArchive: safe.zip
[safe.zip] safe password:
inflating: safe
replace safefile? [y]es, [n]o, [A]ll, [N]one, [r]ename: r
new name: safeb
inflating: safeb
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
safe.zip
cover.zip karate.pdf ... etc ... safe safeb safee.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ gedit safe safeb
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -d safe.zip safe
deleting: safe
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -sf safe.zipArchive contains:
safefile
Total 1 entries (1690 bytes)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
Remove copies of files and zips from locker directory.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ rm safec.zip
Update the first zip with the zip holding the edited safe file.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -ur safee.zip safe.zip
updating: safe.zip (stored 0%)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
Use the zip -m option to remove copies of files left in the locker directory.
zip -re1Tm
To try to fix a zip archive:
Here the broken zip is called karatee.zip.
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -F karatee.zip --out karatef.zip
Fix archive (-F) - assume mostly intact archive
zip warning: bad archive - missing end signature
etc ... zip warning: Can't use -F to fix (try -FF)
zip error: Zip file structure invalid (karatee.zip)
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -FF karatee.zip --out karatef.zip
Fix archive (-FF) - salvage what can
zip warning: Missing end (EOCDR) signature - either this archive
is not readable or the end is damaged
Is this a single-disk archive? (y/n): y
Assuming single-disk archive
Scanning for entries...
zip warning: zip file empty
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
Zip put the out file called karatef.zip in the current directory. But it does not unzip.
Here we first zip the directory holding all the files. Then we move that zip archive into a directory called archi1 in the locker. Then we zip the directory, archi1.
To make a hidden locker with a hidden list of files:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -re1Tm pictr15.zip pictr15
... etc ...adding: pictr15/m02.jpg (deflated 0%)
adding: pictr15/bp_002zczc.wmv (deflated 0%)
adding: pictr15/77585_14big.jpg (deflated 2%)
L-67.jpg (deflated 0%)
[ziMNrkWw] pictr15/03.mpg password:
test of pictr15.zip OK
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
arch1 ics9798m icr1 pictr15.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ mkdir archi1
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
arch1 archi1 ics9798m icr1 pictr15.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ mv pictr15.zip archi1/
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
arch1 archi1 ics9798m icr1
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls archi1
pictr15.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ zip -re1Tm archi1.zip archi1
Enter password:
Verify password:
adding: archi1/ (stored 0%)
adding: archi1/pictr15.zip (stored 0%)
[zi0M1kz9] archi1/pictr15.zip password:
test of archi1.zip OK
user@user-ID:/media/160gbSamsung/home/trevor/.locker$
That way File Roller cannot list the files without the password.
Zip each directory of files that way, one at a time, one zip inside another.
To unlock a locker:
user@user-ID:~$ cd .locker/
bash: cd: .locker/: Permission denied.
user@user-ID:~$ chmod u=rwx------ .locker/
user@user-ID:~$ cd .locker/
user@user-ID:~/.locker$
The chmod command is the key.
To lock the locker:
chmod ugo=--------- .locker/
user@user-ID:~/.locker$ cd ..
One dot means current directory and two means previous directory, one directory back.
user@user-ID:~$ chmod ugo=--------- .locker/
The password for the locker should be different from the one used to log in to the computer.
Try to show what files are in the locker:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ ls
archi1.zip archi2.zip archi3.zip
The arhive names do not hint at what files are in them.
A password is needed to unzip the archive.
/.locker$ unzip archi3.zip
$ ls archi3/
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ unzip archi3/icr1.zip
A password is also needed to show the files.
To remove the history of a password which shows on the Terminal screen:
user@user-ID:/media/160gbSamsung/home/trevor/.locker$ history -c
A password should not show on the Terminal screen.
To try to unzip or decrypt an archive of unknown type:
File Roller only shows an error.
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ ls
gpgarchive.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ unzip gpgarchive.zip
Archive: gpgarchive.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of gpgarchive.zip or
gpgarchive.zip.zip, and cannot find gpgarchive.zip.ZIP, period.
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ gpg -d gpgarchive.zip
gpg: AES256 encrypted data
gpg: encrypted with 1 passphrase
gpg: decryption failed: bad key
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ ls
gpgarchive.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ openssl enc -d -aes-256-cbc -in gpgarchive.zip -out gpgarchived
enter aes-256-cbc decryption password:
bad magic number
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ ls
gpgarchived gpgarchive.zip
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ gedit gpgarchived
That is an empty text file, not a directory of extracted files. Adding sudo to the decrypt commands did not help.
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ zip -F gpgarchive.zip --out gpgarchivefix
Fix archive (-F) - assume mostly intact archive
zip warning: bad archive - missing end signature
zip warning: (If downloaded, was binary mode used? If not, the
zip warning: archive may be scrambled and not recoverable)
zip warning: Can't use -F to fix (try -FF)
zip error: Zip file structure invalid (gpgarchive.zip)
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$ zip -FF gpgarchive.zip --out gpgarchivefix
Fix archive (-FF) - salvage what can
zip warning: Missing end (EOCDR) signature - either this archive
is not readable or the end is damaged
Is this a single-disk archive? (y/n): y
Assuming single-disk archive
Scanning for entries...
zip warning: zip file empty
user@user-ID:/media/160gbSamsung/home/trevor/.locker2$
The archive may have been empty to begin with. Openssl cannot protect an archive file, zip or tar.
Remove the broken archive.
To make a locker for only the root owner to use:
user@user-ID:~$ sudo mkdir ~/.locker/
Also, in Files manager click the locker icon, select properties, emblems and tick the read-only lock icon. Next click the owner user's drop list and select read only and press apply permissions to enclosed files in read-only folders. That makes a hidden locker in the ~/ or /home/trevor/ directory.
To lock the locker:
Here the locker is called .locker3.
username@username-795GHN-Y3L:~$ chmod ugo=---------- .locker3/
To check that the locker is locked:
user@user-ID:~$ cd ~/.locker3/
bash: cd: /home/trevor/.locker3/: Permission denied
user@user-ID:~$
To open the locker:
:~$ chmod ugo=-rw------- .locker3/
Or in Files manager click the file icon, select properties, permissions, owner access, read and write. In Files manager click the locker name, right click and select properties in the drop list, for owner user select create and delete files, close.
To put files or directories into the locker:
First open it with this key command,
:~$ chmod ugo=-rw------- .locker3/
Move or cut and paste files or directories into /home/trevor/.locker/
Do not leave copies behind. Usually it is best to sort files into directories before moving them into the locker.
To check the location and user permissions of the locker:
user@user-ID:~$ sudo ls -al | grep locker
[sudo] password for trevor:
d--------- 3 trevor trevor 4096 2019-08-31 15:09 .locker3
user@user-ID:~$
The locker is in the /home/user/ directory and is locked as it has no permissions.
To list the files and directories in the locker:
user@user-ID:~$ sudo ls -a .locker3/
. .. 2do firewall taradd
user@user-ID:~$
To lock and encrypt a directory full of files in the locker and protect them with a password, use Zip as follows.
First open the locker with the key command:
user@user-ID:~$ chmod ugo=-rw------- .locker3/
user@user-ID:~$ sudo ls -al ~/.locker3/newdir/total 32
drwxr-xr-x 2 root root 4096 2019-09-01 19:58 .
d--------- 3 trevor trevor 4096 2019-09-01 19:18 ..
-rw-r--r-- 1 trevor trevor 83 2019-08-23 07:09 2do
-rw-r--r-- 1 trevor trevor 5643 2019-08-28 16:43 firewall
-rw-r--r-- 1 trevor trevor 10374 2019-08-31 13:20 taradd
Here the locker holds a new directory with three files in it. Zip turns the directory into an encrypted, password-protected file holding the three files.
Change to the unlocked locker directory:
user@user-ID:~$ cd .locker3/
user@user-ID:~/.locker3$
Run the zip command:
user@user-ID:~/.locker3$ sudo zip -re1Tm newdire2.zip newdir2/
Enter password:
Verify password:
adding: newdir2/ (stored 0%)
adding: newdir2/ab28819.png (deflated 3%)
adding: newdir2/commandsjoined (deflated 47%)
adding: newdir2/instalubuntu (deflated 52%)
[ziO0Yic2] newdir2/ab28819.png password:
test of newdire2.zip OK
user@user-ID:~/.locker3$ ls
newdire2.zip newdire.zip
user@user-ID:~/.locker3$
Zip copied the directory called newdir2 with its files into a zip file called newdire2.zip then removed the original directory.
The locker must now be locked as shown above.
Do not type a . dot space, ./ slash space or an option -i in a zip or chmod command. If a dot is typed out of place in a chmod command, Change mode can accidentally deny permissions and all access to the home directory and crash a system.
To recover from such a computer crash with user permissions errors, press ctrl-alt-t then run these commands in Terminal:
sudo chmod u=rwx /
sudo chmod u=rwx /home/
sudo chmod u=rwx /home/trevor/
sudo ls -al /home/trevor/
user@user-ID:~$ sudo ls -al /home/trevor/
[sudo] password for trevor:
ls: total 9740
drwx------ 71 trevor trevor 4096 2019-09-02 12:32 .
drwxr-xr-x 4 root root 4096 2016-11-10 17:40 ..
drwx------ 2 trevor trevor 4096 2014-10-14 08:43 .acetoneiso ... etc ...
Linux will automatically restore a .gvfs/ directory after chmod is used to reset permissions of the user directory.
To make a directory inside a locker:
user@user-ID:~$ sudo mkdir ~/.locker3/newdir/
user@user-ID:~$ sudo ls -a ~/.locker3/
. .. 2do firewall newdir taradd
user@user-ID:~$
The list all -a command shows hidden directories, those with names starting with a dot, including the current directory, one dot, and the parent directory, two dots.
Dots on a command line can be like short-hand for (.) this current Directory and (..) the parent of this directory, that is the directory which contains this directory. The current or present directory is the one selected and shown on the command prompt. Here the current directory is (~) the home directory of the user. The tild ~ means the same as /home/username/ . So a dot . means the home directory called /trevor/, /home/trevor/. The home directory is in / the root directory. The directory called .locker3 is in the currently selected directory called home/. That means there is the / root directory, then home/ for trevor/ then .locker3/ .
To move a file in the locker into a directory in the locker:
user@user-ID:~$ sudo mv .locker3/2do .locker3/newdir/
To remove a file from a directory within a locker:
user@user-ID:~$ sudo rm ~/.locker3/newdir/taradd
To remove a directory from a locker:
Here the directory is called newdir.
user@user-ID:~$ sudo ls -a ~/.locker3/
. .. 2do firewall newdir taradd
user@user-ID:~$ sudo rmdir ~/.locker3/newdir/
user@user-ID:~$ sudo ls -a ~/.locker3/
. .. 2do firewall taradd
user@user-ID:~$
To remove a locker:
user@user-ID:~$ sudo rmdir .locker
Type the name of the locker as it is written on the list, without slashes.
To remove a directory and a file from the current directory:
The first - means file and the initial d means directory.
-rw-r--r-- 1 trevor trevor 1472 2019-09-04 14:03 locker4
drwx------ 2 root root 4096 2019-09-04 11:49 .locker4
user@user-ID:~$ rm ./locker4
user@user-ID:~$ rmdir .locker4/
user@user-ID:~$ ls -al
total 11136
...etc ...
drwx------ 3 trevor trevor 4096 2013-05-15 19:59 .local
drwx------ 3 trevor trevor 4096 2019-09-02 17:51 .locker3
drwx------ 3 trevor trevor 4096 2014-11-22 06:22 .macromedia
drwx------ 2 trevor trevor 4096 2014-08-21 14:01 .me-tv
Both file and directory are gone.
To unzip and encrypt a zip file in the locker:
Unlock the locker,
user@user-ID:~$ sudo chmod u=rwx /home/trevor/.locker3/
List the zip file,
user@user-ID:~$ sudo ls -al /home/trevor/.locker3/
total 16
drwx------ 2 trevor trevor 4096 2019-09-01 20:01 .
drwx------ 71 trevor trevor 4096 2019-09-02 13:08 ..
-rw-r--r-- 1 root root 7603 2019-09-01 20:01 newdire.zip
Change to the locker directory,
user@user-ID:~$ cd /home/trevor/.locker3/
user@user-ID:~/.locker3$
Run unzip,
user@user-ID:~/.locker3$ sudo unzip newdire.zip
Archive: newdire.zip
creating: .locker3/newdir/
[newdire.zip] .locker3/newdir/2do password:
inflating: .locker3/newdir/2do
inflating: .locker3/newdir/taradd
inflating: .locker3/newdir/firewall
user@user-ID:~/.locker3$
Unzip should have copied the files into a directory with the same name as the original directory they were in, /newdir/, and put them in the current locker directory. But it also duplicated the locker directory.
user@user-ID:~/.locker3$ sudo ls -al
total 20
drwx------ 3 trevor trevor 4096 2019-09-02 16:49 .
drwx------ 71 trevor trevor 4096 2019-09-02 16:55 ..
drwxr-xr-x 3 root root 4096 2019-09-02 16:49 .locker3
-rw-r--r-- 1 root root 7603 2019-09-01 20:01 newdire.zip
user@user-ID:~/.locker3$
To edit a file from a directory in an unlocked locker:
user@user-ID:~/.locker3$ gedit ./.locker3/newdir/2do
user@user-ID:~/.locker3
Put new battery in smoke alarm etc ...
To list the files in an unlocked locker:
user@user-ID:~/.locker3$ ls -al ./
total 20
drwx------ 3 trevor trevor 4096 2019-09-02 13:23 .
drwx------ 71 trevor trevor 4096 2019-09-02 14:07 ..
drwxr-xr-x 3 root root 4096 2019-09-02 13:23 .locker3
-rw-r--r-- 1 root root 7603 2019-09-01 20:01 newdire.zip
user@user-ID:~/.locker3$ ls -al ./.locker3/
total 12
drwxr-xr-x 3 root root 4096 2019-09-02 13:23 .
drwx------ 3 trevor trevor 4096 2019-09-02 13:23 ..
drwxr-xr-x 2 root root 4096 2019-09-01 19:58 newdir
user@user-ID:~/.locker3$
If the files in an unzipped directory have not been edited or changed in any way, that directory can be removed as it is backed up in the zip file of the same name.
To rezip and encrypt an unzipped directory full of files in the locker which have been edited, run the zip command again as above but with the name of the unzipped directory. The new zip will replace the old zip of the same name.
To zip another directory and put it in the locker with other zip files, run the zip command again as above with the name of the new zip.
To add files into a zip archive and update it:
zip -u files.zip file3.txt file4.txt
To mount several hard drives in the same computer:
The drive called /dev/sda1 with the operating system has been automatically mounted in the root directory.
Any drive should be mounted into a directory as a mount point. Here a second hard drive called /dev/sdb has been mounted already at /media/user/a16e639*/
user@user-ID:~$ ls /media/user/
a16e639d-c743-4042-858e-85c81eb777bd
user@user-ID:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 977M 0 977M 0% /dev
tmpfs 200M 6.4M 194M 4% /run
/dev/sda1 46G 15G 30G 33% /
/dev/sdb 917G 561G 310G 65% /media/user/a16e639d-c743-4042-858e-85c81eb777bd
A third hard drive called /dev/sdc1 is to be mounted.
user@user-ID:~$ sudo mount /dev/sdc1 /media/user/
That mounts the third hard drive but not in its own directory.
user@user-ID:~$ ls /media/user/
archive182 Backup lost+found
user@user-ID:~$
List shows the two directories of the third hard drive but not the second hard drive, although both drives are mounted.
The third drive needs a directory as a mount point.
user@user-ID:~$ sudo umount /dev/sdc1 /media/user/
umount: /media/user/: not mounted
user@user-ID:~$ ls /media/user/
1TBFilesys a16e639d-c743-4042-858e-85c81eb777bd
List shows two directories, one ready for the third drive and the other holding the second drive.
user@user-ID:~$ sudo mount /dev/sdc1 /media/user/1TBFilesys/user@user-ID:~$ ls /media/user/1TBFilesys/
archive182 Backup lost+found
user@user-ID:~$
List now shows the two directories in a directory named after the third hard drive and also shows the second hard drive. Device Finder shows three hard drives, the second one being called /dev/sdb/ .
user@user-ID:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 977M 0 977M 0% /dev
tmpfs 200M 6.4M 194M 4% /run
/dev/sda1 46G 15G 30G 33% /
tmpfs 998M 284K 998M 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 998M 0 998M 0% /sys/fs/cgroup
tmpfs 200M 52K 200M 1% /run/user/1000
/dev/sdb 917G 561G 310G 65% /media/user/a16e639d-c743-4042-858e-85c81eb777bd
/dev/sdc1 917G 674G 198G 78% /media/user/1TBFilesys
user@user-ID:~$
Linux with Ubuntu file manager may mount drives at different mount points at different times.
To see how much memory the computer has and is using, run this command.
cat /proc/meminfo
or run the command: free
To show how much memory each program is using, run top:
top
wn@wn-xps:~$ top
To check how much memory is free, run vmstat.
wn@wn-xps:~$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 2480852 39664 259008 0 0 36 6 80 243 2 0 97 1
wne@wne-xps:~$
wne@wne-xps:~$ cat /proc/meminfo
MemTotal: 1023048 kB
MemFree: 388408 kB
etc ...
That is 1gb of RAM memory.
or wne@wne-xps:~$ free
total used free shared buffers cached
Mem: 3093532 632016 2461516 0 38784 255984
-/+ buffers/cache: 337248 2756284
Swap: 6910972 0 6910972
wne@wne-xps:~$
Here the Linux commands do not show the total memory as shown in BIOS setup. This is because the OS is an old, 32bit version by Ubuntu. A 64bit OS operating system will show and use all the memory.
Here the cat command is repeated after a second RAM card has been put into the main board.
wn@wn-xps:~$ cat /proc/meminfo
MemTotal: 3093532 kB
MemFree: 2738376 kB
then with a third RAM card,
wne@wne-xps:~$ cat /proc/meminfo
MemTotal: 3352348 kB
MemFree: 3005860 kB
but with a fourth card the memory has not increased,
wne@wne-xps:~$ cat /proc/meminfo
MemTotal: 3352348 kB
MemFree: 2992988 kB
So the fourth card or socket may have failed or may not be firmly in the socket.
wne@wne-xps:~$ cat /proc/meminfo
MemTotal: 3093532 kB
MemFree: 2726780 kB
That is after the 4th card has been replaced.
So the fourth slot may be faulty.
No; F2 BIOS setup shows this amount of memory:
2gb in slot1, 1gb in slot 2, 1gb in slot3 and 0.5gb in slot 4.
Total is 4.5 gb.
Linux is not showing the right amount of memory.
BIOS also recognises the other 0.5 card in slot4. So that card is probably not faulty either.
Ubuntu Linux 32 bit OS probably does not recognise all the memory whereas a 64bit version of the OS would should recognise and use all 4.5gb.
Find command in Linux
https://www.geeksforgeeks.org/find-command-in-linux-with-examples/
see also findarchivec.txt
To search for a file in a subdirectory of the current directory:
$ find ./subdirectoryname -name filename.txt
To search for all files in the current directory which have file names ending in .txt:
$ find . -name *.txt
To find and delete a file, with a yes or no prompt:
$ find ./GFG -name sample.txt -exec rm -i {} \;
To look for empty files and directories:
$ find ./directoryname -empty
To search for a word within many files:
This command uses find and grep.
$ find ./ -type f -name "*.txt" -exec grep 'Geek' {} \;
This command print lines which have ‘Geek’ in them and ‘-type f’ specifies the input type is a file.
===
find
https://www.howtoforge.com/tutorial/linux-find-command/
To find and list all the files in the current directory and its subdirectories, type find without any options:
$ find
The find command automatically searches in all sub-directories.
To list all files in another directory, type the name of that directory into the find command.
$ find directorypath
To find a file by its name:
$ find directorypath -name filename
To find a file in the current . directory:
find . -name testfile1.txt
To find a file in a different directory:
Find automatically searches in all sub-directories by default.
S find /directoryname -name filename.txt
To find and show all files of a type in the current directory, type an * wildcard:
find . -name "*.txt"
Find is by default sentitive to upper and lowercase letters when it searches for a filename.
To tell Find to ignore case when seaching, type the -i option:
find -iname testfile.txt
To find a file in the current directory without looking in any subdirectories:
find . -maxdepth 1 -name "filename.txt"
To tell Find to search only the subdirectories of the current directory:
find . -mindepth 2 -name "*.txt"
Minimum and maximum depth options can both be used in the same command.
To show all the empty files in the current directory and its subdirectories:
$ find . -empty
++++
https://linuxhint.com/view_zip_archive_contents_linux/
To show the files in a zip archive without extracting them:
$ zip -sf archivename.zip
That shows a list of the files in the archive without decompressing them.
Zip, unzip, zmore, zless, zcat and gzip come installed with Ubuntu Linux. Vim does not.
These commands work for zip files but not for zipped folders.
$ zmore archivename.zip
or $ zless archivename.zip
Press q key to exit zless display.
or zcat archivename.zip
If zcat is run for a zip folder, it will show only one file and ignore the rest.
Or run Vim:
vim archivename.zip
Vim works for zip archive files and for zip archive folders too.
To show a list of the files in a zip-archived folder:
$ unzip –l archivename.zip
To show what is in all the files in a zip archive:
$ unzip -c archivename.zip
Then run
$ unzip –c < archive_name> filename
to see what is in one of the files in the archive folder.
To change to a directory on a second hard drive of the the computer:
Firsts mount the second device.
user@user-TI:~$ cd /media/user/1TBFilesys/archive182/.vlc/
user@user-TI:/media/user/1TBFilesys/archive182/.vlc$
To list all the zipped folders or files in the current directory:
user@user-TI:/media/user/1TBFilesys/archive182/.vlc$ ls
1read ext167.zip ext253.zip ext85.zip archive154.zip archive34.zip etc
To show what zip archive file is within a zipped folder:
Here a zipped folder called archive44 holds one zipped archive file called files16.zip .
user@user-TI:/media/user/1TBFilesys/archive182/.vlc$ unzip -l archive44.zip
Archive: archive44.zip
Length Date Time Name
--------- ---------- ----- ----
0 2019-10-07 12:12 archive44/
547933783 2019-10-05 13:41 archive44/files16.zip
--------- -------
547933783
To find where a new file has been cached, saved or missaved, run the find command to look for files modified in the last 5 minutes:
find ~ -type f -mmin -5
There ~ means the home directory.
user@localhost-ID:~$ find ~ -type f -mmin -5/home/jim/.config/dconf/user
/home/jim/.local/share/recently-used.xbel
/home/jim/.local/share/zeitgeist/activity.sqlite-wal
/home/jim/.local/share/zeitgeist/activity.sqlite-shm
/home/jim/.local/share/gvfs-metadata/home
/home/jim/.local/share/gvfs-metadata/home-5f35eab9.log
find: ‘/home/jim/.dbus’: Permission denied
find: ‘/home/jim/.cache/dconf’: Permission denied
/home/jim/Desktop/find5sudo
user@localhost-ID:~$
user@localhost-ID:~$ sudo ls /home/jim/.cache/dconf
[sudo] password for jim:
user@localhost-ID:~$
Nothing is in that cache directory.
Gnome Zeitgeist is logging all activity on the system and slowing it down.
To check if a daemon is running:
ps -ef |grep zeit
Here the daemon is called zeit.
user@localhost-ID:~$ ps -ef |grep zeit
jim 2260 1875 0 07:41 ? 00:00:00 zeitgeist-datahub
jim 2267 1667 0 07:41 ? 00:00:00 /bin/sh -c /usr/lib/x86_64-linux-gnu/zeitgeist/zeitgeist-maybe-vacuum; /usr/bin/zeitgeist-daemon
jim 2271 2267 0 07:41 ? 00:00:00 /usr/bin/zeitgeist-daemon
jim 2278 1667 0 07:41 ? 00:00:00 /usr/lib/x86_64-linux-gnu/zeitgeist-fts
jim 6672 6462 0 13:58 pts/0 00:00:00 grep --color=auto zeit
user@localhost-ID:~$
To allow zeitgeist logging:
chmod -rw
chmod -rw ~/.local/share/zeitgeist/activity.sqlite
To deny zeitgeist logging:
+rw
$ chmod +rw ~/.local/share/zeitgeist/activity.sqlite
https://linuxaria.com/howto/how-to-remove-zeitgeist-in-ubuntu-and-why
To find any command, search for it using grep. The grep command below has three options: r recursively look into all the directories and files within this directory called sudo; i ignoring whether the key word has upper or lower letters; and H to print the name of the file with any line which includes the keyword. Use quotes if keywords have space between them. Here the key word is "$ zip" as the search is for zip commands. A command found can be copied, pasted and run in Terminal. For instructions, run gedit to open the text file named at the beginning of the line, for example $ gedit ./linuxsudob10b, where the current directory ./ is /sudo.
To find the sudo directory on a backup hard drive, run the ls lsit and cde change directory commands one after the other until you reach the directory called sudo.
Start with ls /media/
cd /media/
and finish with
username@websitename:/media/name/05f11de0-e246-4508-9fd1-581e1bcb4b08/home/name/Documents$ cd /media/name/05f11de0-e246-4508-9fd1-581e1bcb4b08/home/name/Documents/sudo/
username@websitename:/media/name/05f11de0-e246-4508-9fd1-581e1bcb4b08/home/name/Documents/sudo$ ls
To find all files in the ./ current directory which mention the word "grep", run this grep command:
grep -riH "searchword" ./
username@websitename:/media/name/05f11de0-e246-4508-9fd1-581e1bcb4b08/home/name/Documents/sudo$ grep -riH "grep" ./
See output like
./linuxsudo153:Or pipe parted output to grep.
./linuxsudo153:user@user-K66B-HG2:~$ sudo parted -l | grep /dev/
Here the file called linuxsudo153 may be the best file about grep commands.
To run a calculator in Terminal:
$ calc
See calchow.txt for how to use calculators on a command line.
To read one of many tutorials for beginners of Linux, browse to
http://linuxsurvival.com
or type a command name and tutorial into a search engine, eg echo tutorial .
The df command is used in Terminal to find the amount of free space left on a hard drive, as follows.
ayne@ayne-G31MX-S2:~$ df /dev/sda1
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 301617648 214167808 72128548 75% /
ayne@ayne-G31MX-S2:~$ df /dev/sdh1
Filesystem 1K-blocks Used Available Use% Mounted on
none 1019684 300 1019384 1% /dev
ayne@ayne-G31MX-S2:~$ df /dev/sdb1
Filesystem 1K-blocks Used Available Use% Mounted on
none 1019684 300 1019384 1% /dev
ayne@ayne-G31MX-S2:~$ df /dev/sdc1
Filesystem 1K-blocks Used Available Use% Mounted on
none 1019684 300 1019384 1% /dev
user@host-ID:~$
Something looks amiss with the 1% information above; three different hard drives having the same amount of space free?
Ubuntu's Disk Utility and Disk Usage Analyzer don't do the job either.
With the failing drive unplugged, Terminal sees: -
user@host-ID:~$ df /dev/sda1
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 301617648 214168280 72128076 75% /
user@host-ID:~$ df /dev/sdb1
Filesystem 1K-blocks Used Available Use% Mounted on
none 1019688 280 1019408 1% /dev
user@host-ID:~$ df /dev/sdc1
Filesystem 1K-blocks Used Available Use% Mounted on
none 1019688 280 1019408 1% /dev
user@host-ID:~$
Use Ubunty drive utility to check all HDD device locations like eg 320gb HDD device /dev/sda1
FDclone is not installed on this archive computer and Synaptic cannot install it because it is not available at the mirror repositories for Ubuntu 10.
RAM
To check the amount of RAM memory of a computer, run Terminal and execute either or both these commands:
free -m
or cat /proc/meminfo
eg With on 500mg and one 250mg ram cards in the computer, the total is about 0.75GB of memory, as confirmed in the information below.
user7@user7-945GZM-S2:~$ cat /proc/meminfo
MemTotal: 758712 kB
MemFree: 75556 kB
Buffers: 114476 kB
Cached: 253524 kB
SwapCached: 0 kB
Active: 242916 kB
Inactive: 246836 kB etc
LowFree: 75556 kB
SwapTotal: 1951740 kB
SwapFree: 1951740 kB
Dirty: 48 kB
Writeback: 0 kB
AnonPages: 121752 kB
Mapped: 49176 kB
Shmem: 71816 kB
Slab: 147276 kB
SReclaimable: 138172 kB etc
DirectMap4M: 757760 kB
user7@user7-945GZM-S2:~$
user7@user7-945GZM-S2:~$ free -m
total used free shared buffers cached
Mem: 740 667 73 0 111 247
-/+ buffers/cache: 308 432
Swap: 1905 0 1905
user7@user7-945GZM-S2:~$
see also freedisksudo,txt
To clear all the temporary files out of the /tmp directory, reboot the computer. Otherwise run this find command:
sudo find /tmp -type f -delete
f is for files
user@host-ID:~$ sudo find /tmp -type f -delete
[sudo] password for user:
user@host-ID:~$ ls /tmp
ssh-xGUX3fuQHqTU
systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-colord.service-uygtik
systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-rtkit-daemon.service-Q6J4AU
user@host-ID:~$ ls /tmp/ssh-xGUX3fuQHqTU
agent.1807
user@host-ID:~$
The find command deletes files but not folders or directories. Here three directories are left. One holds a file, as the list command shows. Its magenta or purple file name shows that it is a graphic, image or video file. Rebooting did not delete this file.
user@host-ID:~$ ls /tmp/systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-colord.service-uygtik
ls: cannot open directory '/tmp/systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-colord.service-uygtik': Permission denied
user@host-ID:~$ sudo ls /tmp/systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-colord.service-uygtik
tmp
user@host-ID:~$
The second directory is empty, as it should be after deleteing with find.
user@host-ID:~$ sudo ls /tmp/systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-rtkit-daemon.service-Q6J4AU
tmp
user@host-ID:~$
The third directory is empty too.
To remove folders and files from the temporary directory:
user@host-ID:~$ cd /tmp
user@host-ID:/tmp$ ls
ssh-xGUX3fuQHqTU
systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-colord.service-uygtik
systemd-private-3dd0a1336c544eb1b42e0c8afdeccf8e-rtkit-daemon.service-Q6J4AU
user@host-ID:/tmp$ sudo rm -rf *
[sudo] password for user:
user@host-ID:/tmp$ ls
user@host-ID:/tmp$
On rebooting the computer, Linux has replaced the three folders but the magenta file is zero bytes.
To display free disk space:
user@host-ID:~$ cd /
user@host-ID:/$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 6.5M 389M 2% /run
/dev/sda3 5.8G 5.5G 56K 100% /
tmpfs 2.0G 47M 1.9G 3% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 395M 112K 395M 1% /run/user/1000
user@host-ID:/$
The "df -Th" command will display the same output as in the previous command but also includes file system types:
[root@smatteso-vm1 usr]# df -T -h
user@host-ID:/$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 395M 6.5M 389M 2% /run
/dev/sda3 ext4 5.8G 5.5G 108K 100% /
tmpfs tmpfs 2.0G 47M 1.9G 3% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs tmpfs 395M 112K 395M 1% /run/user/1000
user@host-ID:/$
https://www.techrepublic.com/article/how-to-free-disk-space-on-linux-systems/
To show disk usage run this command, using an asterisk * for all disks:
The switches -sh mean "s" for "summarize" and "h" for "human readable format".
user@host-ID:/$ sudo du -sh *
13M bin
59M boot
4.0K cdrom
1.4M dev
13M etc
1.7G home
0 initrd.img
424M lib
4.0K lib64
16K lost+found
84K media
8.0K mnt
4.0K opt
du: cannot access 'proc/4204/task/4204/fd/4': No such file or directory
du: cannot access 'proc/4204/task/4204/fdinfo/4': No such file or directory
du: cannot access 'proc/4204/fd/4': No such file or directory
du: cannot access 'proc/4204/fdinfo/4': No such file or directory
0 proc
52K root
du: cannot access 'run/user/1000/gvfs': Permission denied
6.5M run
13M sbin
4.0K snap
4.0K srv
0 sys
52K tmp
2.9G usr
473M var
0 vmlinuz
user@host-ID:/$
Note that access is denied to the git virtual file system, gvfs.
To look at the size of the fullest sub directories, run this command without an asterisk:
du -a /var | sort -nr | head -n 10
Here du is the disk usage command,
-a shows all items.
/var tells du to scan the /var directory.
The pipe | character pipes the results to the sort command.
sort -nr will display the largest directories at the top of the list.
The pipe | character pipes the results to the head command.
The head -n 10 will limit the number of results to the top ten largest directories.
user@host-ID:/$ sudo du -a /var | sort -nr | head -n 10
[sudo] password for user:
483356 /var
367396 /var/lib
270660 /var/lib/apt
270608 /var/lib/apt/lists
107064 /var/cache
82548 /var/cache/apt
65040 /var/lib/dpkg
60860 /var/lib/dpkg/info
41388 /var/cache/apt/pkgcache.bin
41140 /var/cache/apt/srcpkgcache.bin
user@host-ID:/$
To filter the results of disk usage du more:
du -xh / |grep '^\S*[0-9\.]\+G'|sort -rn
The -x tells du to only check this file system (makes the command run faster) and the h after it is to present results in human readable format.
The pipe ("|") character pipes the results to the grep command.
grep searches the results using the '^\s*[0-9\.]\+G' regex - [0-9\.] will list all directories and subdirectories beginning with (^\S) non-whitespace characters (such as a tab, carriage return, etc.) - it must show alpha characters only (no numeric characters) and +G will display directories 1 Gb in size or larger.
The pipe ("|") character pipes the results to the sort command.
sort -rn will display the largest directories at the top of the list.
user@host-ID:/$ sudo du -xh / |grep '^\S*[0-9\.]\+G'|sort -rn
[sudo] password for user:
5.5G /
2.9G /usr
1.7G /usr/lib
1.7G /home/user
1.7G /home
1.1G /home/user/Programs
user@host-ID:/$
To find large files which are using a lot of space on the drive, run the find command:
user@host-ID:/$ sudo find / -printf '%s %p\n'| sort -nr | head -10
sort: write failed: /tmp/sortGZv3ql: No space left on device
user@host-ID:/$
The drive is almost full; not enough space left on it.
Deleting files can be dangerous to the system.
dnsmask - Dnsmasq does DHCP, DNS, DNS caching, and TFTP and works with both dynamic and static ip addresses at the same time.
Before running dnsmasq, the local network must be running and correctly configured.
To find if dnsmaq is installed:
dnsmasq: failed to create listening socket for port 53: Permission denied
user@host-ID:~$ sudo dnsmasq
or
dnsmasq: failed to create listening socket for port 53: Address already in use
user@host-ID:~$
Yes it is installed.
To check if port 53 is open:
user@host-ID:~$ sudo ufw allow 53
Skipping adding existing rule
Skipping adding existing rule (v6)
user@host-ID:~$
53 is already open.
To show the encryption of a file:
Open the zip file in gedit or another text editor.
These two lines below
Encryption: Private key password mail captcha certificate SSH classified blocked blacklist.
look like this when encrytped as a zip file called encrypted.zip
PK\00 \00\00\A6P\ACV\8A\A3\8Da\00\00\00]\00\00\00 \00\00encryptedUT \00\B7\82]d\B7\82]dux\00\E8\00\00\E8\00\00\BBs+\D3\E5!\E5rny\BC\93su{o@B\B6\AF\CF\A7 \00e\9F4p9\85H \93\AE^\85\82̃\CDE\8DL\8F~C\98\BE\81'J\805uK\BD\8C\B8\BA}\FApieIO\E9\E5\B5J\AE\E47\E3t\D8[`0\DBk4!(PK\8A\A3\8Da\00\00\00]\00\00\00PK\00 \00\00\A6P\ACV\8A\A3\8Da\00\00\00]\00\00\00 \00\00\00\00\00\00\00\00\00\B4\81\00\00\00\00encryptedUT\00\B7\82]dux\00\E8\00\00\E8\00\00PK\00\00\00\00\00\00O\00\00\00\B4\00\00\00\00\00
Notice that the encryption shows that the file is called encrypted.zip as the word encryption is the only word not encrypted and the letters PK stand for the PKZip program. That is verified in the following encryption of a text file called encoding.
PK
\00 \00\00\00nR\ACVeW"F\00\00\00:\00\00\00\00\00encodingUT \00\86]d\86]dux\00\E8\00\00\E8\00\00\AE}\94+j\9E\F1ˤk\FF\B4\93\9B\00\DDU\FE@3\AE\DF\FD
@w'\E0v\E8\D9\E1yZ\89X\A5\F0PN\81g\A1\BFIS\D6
P\BD`\DD\E9#\9D\FB\93;\FEi(\AD?PKeW"F\00\00\00:\00\00\00PK
\00 \00\00\00nR\ACVeW"F\00\00\00:\00\00\00\00\00\00\00\00\00\00\00\00\B4\81\00\00\00\00encodingUT\00\86]dux\00\E8\00\00\E8\00\00PK\00\00\00\00\00\00N\00\00\00\98\00\00\00\00\00
PKZip
support.pkware.com/home/pkzip/pkzip-securezip...
PKZIP enables you to create and extract from many other archive types besides ZIP.
The text file of the zip file opened in the text editor has a name ending with binary.
To save encryption code in a binary file as a text file, rename the binary file with a .txt ending.
Do not post any encrypted lines into the text of an email.
To email a zip file or any other encrypted file, send it as an attachment.
To recover lost files from the disk of a formatted hard drive:
Here a failed hard drive was reformatted as ext4 Linux.
Run the Foremost data recovery program.
jim@jim-PD3:~$ sudo foremost -t gif,bmp,png,jpg -T -i /dev/sda1 -o /media/jim/LACIE/Recovered
[sudo] password for user:
Processing: /dev/sda1
That command recovers files from a failed hard drive installed as a slave in another computer and copies them to a removable USB drive called Lacie.
The hard drive being recovered from has to be seen by BIOS CMOS. The location of the partition to be recovered from must be shown in the command, eg /dev/sda1. It does not matter which operating system is on the drive, whether the file manager sees the file or not, whether files have been deleted or emptied from the bin or not, or whether the drive has been quick reformatted. If the partitions of the drive have been thoroughly reformatted, with zeros overwriting files, then the files will not be recoverable. Drive Utility usually recognises a failing drive and shows its location even when Nautilus file mananger does not.
If a hard drive is not mounted, start Disks Utility, select the drive and partition to be mounted, mount the partition. If Disks cannot mount it, give the partition a quick foremat only then mount it. If the hard drive can be mmounted, Foremost will recover files from it.If the hard drive cannot be run as master becasue the user has a password, format the partition as above then mount it.
Telnet is both a protocol that uses TCP and the name of a program that uses telnet. Telnet is considered an insecure protocol because the connection is not encrypted but for BBS purposes that does not matter.
To show a command line for Telnet, run this command in Terminal:
user@user-computer-id:~$ telnet
telnet>
Or to return to telnet, type quit:
user@user-computer-id:~$ telnet jabber.org 5222
Trying 208.68.163.218...
Connected to jabber.org.
Escape character is '^]'.
quit
telnet>
To return to the Terminal command line, type quit.
telnet> quit
user@user-computer-id:~$
To suspend telnet and go the a terminal command line, type z:
user@user-computer-id:~$ telnet jabber.org 5222
Trying 208.68.163.218...
Connected to jabber.org.
Escape character is '^]'.
z
Connection closed by foreign host.
user@user-computer-id:~$
To close a telnet connection:
user@user-computer-id:~$ telnet jabber.org 5222
Trying 208.68.163.218...
Connected to jabber.org.
Escape character is '^]'.
close
Connection closed by foreign host.
user@user-computer-id:~$
To show help for telnet:
telnet> help
Commands may be abbreviated. Commands are:
close close current connection
logout forcibly logout remote user and close the connection
display display operating parameters
mode try to enter line or character mode ('mode ?' for more)
open connect to a site
quit exit telnet etc
To test the connectivity of a remote host on a given port:
telnet domain name or ip address portnumber
telnet 192.168.0.10 25
A blank screen means the port is open.
An error message means the port is closed or the remote server is not listening on that port.
user@localhost-id:~$ telnet rpc.acronis.com 443
Trying 69.20.59.84...
Connected to rpc.acronis.com.
Escape character is '^]'.
Blank screen below means connected ready for telenet commands.
A port may be blocked by a firewall. A domain name may need to start with http or https.
To let Telnet use port 23 to go through the firewall:
ufw allow
user:~$ sudo ufw allow 23
[sudo] password for name:
Rule added
Rule added (v6)
user:~$
Run that same ufw command on the other computers in the local network so that Telnet can connect through the firewall.
To show your hostname:
hostname
user:~$ hostname
hostnameshown
user:~$
eg jim@tomt-ID:~$ hostname
jim@tomt-ID
jim@tomt-ID:~$
Use the hostname as your local email address.
Email address is jim@tomt-ID
fsck - To check and fix the file system: -
Show the hard drive partitions of the file system by running parted.
user@user-945GCM-S2L:~$ sudo parted /dev/sda 'print'
[sudo] password for user:
Model: ATA ST380013AS (scsi)
Disk /dev/sda: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 76.7GB 76.7GB primary ext4 boot
2 76.7GB 80.0GB 3305MB extended
5 76.7GB 80.0GB 3305MB logical linux-swap(v1)
user@user-945GCM-S2L:~$
The flags are the numbers of each partition. So the first partition device here is called /dev/sda1 .
Be sure to unmount the partition before checking it.
umount /dev/sda1
user@user-945GCM-S2L:~$ sudo umount /dev/sda1
[sudo] password for user:
Run the file system check.
sudo fsck -a -MARfy /dev/sda1
Option -a tells fsck to fix errors automatically, -A tells Fsck to check all the systems, option M stops the check from running on a mounted partition, -f forces fsck to clean the system and -y says yes to messages about errors which fsck can fix safely. Fsch checks the root file system first. Option -R tells fsck not to check the root filesystem, in case that system has been mounted read write.
Fsck shows a code number 1 when it has finished checking and fixing the files on the system.
The keyboard format and language are set up during the installation of Ubuntu. The settings can be changed later.
To change the language and layout or format of the keyboard:
Click the two letters and colon at the top right of the screen. The letters may be en for english, us for United States english, cm for cameroon, or whatever country or language.
On the droplist, select the language wanted.
The keyboard will stay in the language last selected even after the computer is rebooted.
To setup the keyboard, run this command in terminal:
sudo nano /etc/default/keyboard
There are the keyboard settings.
Find the line
XKBLAYOUT="xx"
Type us for US english instead of xx. The default language is us.
To edit the keyboard settings manually:
The standard location of the keyboard file is
/etc/default/keyboard.
XKBLAYOUT Specifies the XKB keyboard layout name. This is usually the country or language type of the keyboard. Default: us on most platforms
You can edit /etc/default/keyboard manually instead of running
dpkg-reconfigure keyboard-configuration
Here are three examples:
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) and xkeyboard-config(7) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us,de,fr,ua,ru"
XKBVARIANT=""
XKBOPTIONS="grp:alt_shift_toggle"
BACKSPACE="guess"
To configure the keyboard, edit the file to read like this:
username@loocalhost-id:~$ cat /etc/default/keyboard
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
username@loocalhost-id:~$
That configuration is for US english with Ubuntu18. The next is for British english for Ubuntu 22. Both genetic configurations work with IBM, Logitec and other keyboards.
Standard abreviations apply so uk works but gb may not.
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="uk"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
The keyboard works well with language-support uninstalled.
To find the ip address of each computer on the local network:
username@loocalhost-id:~$ sudo ifconfig -a
[sudo] password for user:
enp5s3 Link encap:Ethernet HWaddr 00:0f:b5:fd:af:f4
inet addr:184.265.2.113 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::b813:3399:2650:ae9a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5388 errors:0 dropped:0 overruns:0 frame:0
TX packets:4425 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3220995 (3.2 MB) TX bytes:467041 (467.0 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:573 errors:0 dropped:0 overruns:0 frame:0
TX packets:573 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:72796 (72.7 KB) TX bytes:72796 (72.7 KB)
username@loocalhost-id:~$
There is the IPv4 address of this computer - inet addr:184.265.2.113
Run the same command on the other computer.
The IP address of the second computer is 184.265.2.114
To test the connections of the local area network, ping data packages from one computer to the others.
username@loocalhost-id:~$ ping 184.265.2.114
PING 184.265.2.114 (184.265.2.114) 56(84) bytes of data.
64 bytes from 184.265.2.114: icmp_seq=1 ttl=64 time=0.438 ms
64 bytes from 184.265.2.114: icmp_seq=2 ttl=64 time=0.273 ms etc
^C
--- 184.265.2.114 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5109ms
rtt min/avg/max/mdev = 0.245/0.287/0.438/0.071 ms
username@loocalhost-id:~$
username@loocalhost-id:~$ ping -c3 192.168.1.100
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=0.179 ms
64 bytes from 192.168.1.100: icmp_seq=2 ttl=64 time=0.102 ms
64 bytes from 192.168.1.100: icmp_seq=3 ttl=64 time=0.102 ms
--- 192.168.1.100 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2053ms
rtt min/avg/max/mdev = 0.102/0.127/0.179/0.038 ms
username@loocalhost-id:~$
The local network is working but DHCP keeps changing the IP addresses and swaping them over from one computer to another. DHCP can sabotage the LAN. Each computer on the network needs a fixed, static IP address.
To run Links internet browser:
see linksinstall.txt
To check where Links installs its executable start file:
ken@hostcomputer-id:~$ ls /usr/local/bin/
links
ken@hostcomputer-id:~$
See the green executable file for Lynx browser.
To start links, run this command in terminal:
links
To show menu bar in links, click with the cursor on the top left corner of the window, or press the esc key.
To go to a website on the internet:
top menu, file, go to url, type in the web address, press enter.
To follow a hyperlink on a web page:
Put cursor on link, press enter key.
To bookmark a page:
Top menu, file, bookmarks, add, ok, close.
To show links to images:
menu bar, search, html options, click display links to images and show names of images.
To show or edit preferences for the browser:
Top menu, edit, preferences.
To show, clear or setup cookies:
menu, setup, cookies
To set history options:
menu, setup. miscellaneous, toggle history.
To close the top menu bar of Terminal:
view, untick toggle toolbar.
To leave the terminal page and go back to the links page, close the terminal page.
To leave a web page and go to an open text file:
click the name of the text file on the menu line at bottom of screen.
Links is not installed from within the Ubuntu package.
To instal links, run this command in Terminal:
apt-get install links
To install software from source code instead of packages, run sudo configure make and install commands.
To installed software from source code, run the commands:
./configure
make
make install
Make and Install are already installed along with the Ubuntu operating system. Configure is not a program. Each package of source code has a ./configure script or a makefile in it. Cd to the extracted package and run the name of the config file or makefile as a command. The command ./configure is usually run before the make and install commands.
Run invoke configure as ./configure in the current directory where the package has been extracted. That calls the right configure script for the extracted files.
To install source code, follow this procedure:
Download the source code from an internet site.
Extract the files out of the downloaded tar package.
Read the file call readme.
Run the configuration script.
Check the makefile.
Run make.
Check file permissions,
Run make install.
Most source-code packages contain a ./configure script that can be run as a script to prepare the code and system ready to be complied.
First read the readme file included with the distribution to explain the install procedure.
To find if any dependencies like library files are needed but missing from the system, run the configure command. If files are missing, the configure script will stop and name them.
When all the dependencies are ready, the script will make a makefile.
By default, software is usually installed in the /usr/local directory.
To installed a program in a different directory, run the configure script with a --prefix prefix option:
./configure --prefix=/usr/local/mysoftware/
The best directory to install into is /usr/local/bin because that separates binary files which are not part of the original linux distribution. To check that the bin folder is there:
pete@pete-ID:~$ ls /usr/local/
bin etc games include lib man sbin share src
pete@pete-ID:~$
To show all options for the ./configure command:
./configure --help
To configure the software package to be installed and its file dependencies:
./configure
Unix and Linux programs are written in a language called C or C++ . They need a C compiler program to build them.
Configure finds the name of the compiler and changes a makefile template to suit the operating system.
To build or make the software:
make
Make reads the makefile of the software package then makes the program from the source code of the tar ball package.
Install copies the files of the made program to the right destination directories.
To install a C compiler called cmake:
pete@pete-ID:~$ cmake
Command 'cmake' not found, but can be installed with:
sudo snap install cmake # version 3.27.7, or
sudo apt install cmake # version 3.22.1-1ubuntu1.22.04.1
See 'snap info cmake' for additional versions.
pete@pete-ID:~$
To install the make command onto the system, run:
sudo apt-get install make
To check if make and install are installed:
pete@pete-ID:~$ gcc
gcc: fatal error: no input files
compilation terminated.
pete@pete-ID:~$
The gcc commands shows that make is already installed.
pete@pete-ID:~$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, .Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
The following make programs can be installed after the linux system is installed.
pete@pete-ID:~$
pete@pete-ID:~$ umake
Command 'umake' not found, but can be installed with:
sudo snap install ubuntu-make
pete@pete-ID:~$
pete@pete-ID:~$ make
Command 'make' not found, but can be installed with:
sudo apt install make # version 4.3-4.1build1, or
sudo apt install make-guile # version 4.3-4.1build1
pete@pete-ID:~$ install
install: missing file operand
Try 'install --help' for more information.
pete@pete-ID:~$ install --help
pete@pete-ID:~$ gmake
Command 'gmake' not found, but can be installed with:
sudo apt install make # version 4.3-4.1build1, or
sudo apt install make-guile # version 4.3-4.1build1
pete@pete-ID:~$
pete@pete-ID:~$ build
Command 'build' not found, did you mean:
command 'xbuild' from deb mono-xbuild (6.8.0.105+dfsg-3.2)
command 'guild' from deb guile-2.2-dev (2.2.7+1-6build2)
command 'guild' from deb guile-3.0-dev (3.0.7-1)
command 'buildd' from deb buildd (0.81.2ubuntu6)
command 'pbuild' from deb pbuilder-scripts (22)
command 'sbuild' from deb sbuild (0.81.2ubuntu6)
command 'obuild' from deb ocaml-obuild (0.1.10-3build1)
Try: sudo apt install
pete@pete-ID:~$
To find the default directory into which software packages are installed, instal a package then look for it.
The default directories to install to are often /usr and /usr/local
Make program can use the Diff program, both of which are installed with the Linux system program. Or diff can be installed with diffutils package.
To install diff:
Here diff is being installed to the user binary directory /usr/bin/
$ make install
$ ls -l /usr/bin/diff
-rwxr-xr-x 1 root root 1078184 Jun 6 11:21 diff
To change the directories where make install will install the files:
–prefix= – This is usually /usr or /usr/local by default, and it is the prefix used in other parameters
–libdir= – This is the libraries directory, and it’s usually ${prefix}/lib or ${prefix}/lib64 by default
–bindir= – This is the executables directory, and it’s usually ${prefix}/bin by default
We can see that libdir and bindir use the prefix parameter by default. Therefore, we can change the installation directory just using the prefix argument.
Users without root privileges can install programs into the /home directory
To list all the directories in the current directory, run the command dir without options flags:
dir
A flag is an option, typed after a command. Here for example the command is gcc and the flag is -c
command flag
gcc -c
To remove an installed program:
rm make clean
$ rm -r /home/username/diffutils
$ make clean
./configure --prefix=/usr
make
There the destination directory is /diffutils
A package usually provides a ./configure script to change its configuration. The configuration file is ./configure
To change a configuration, run the commands:
./configure
make DESTDIR=/home/username/diffutils install
To install a package into /usr/local by default, set prefix to /usr and libdir to /usr/lib64:
$ ./configure --prefix=/usr --libdir=/usr/lib64
Instead of a ./configure script, some packages have a makefile. If the package does have a config file, the Makefile command will override the variables in it.
To invoke or tell the compiler what to do:
gcc instructions
To make or compile a C program from three files:
gcc file1.c file2.c file3.h
Gcc makes an executable a.out file as its target.
Make decides what dependencies and updates are needed.
Linux make Command Options
The make command is widely used due to its effectiveness, variety, and the ability to perform specific actions. While the command prints result when run without options, adding arguments expands make's usability.
The syntax of make commands is:
make options
Here are the most used options:
Command Description
-B, --always-make Unconditionally compiles all targets.
-d, --debug[=FLAGS] Prints the debugging information.
-C dir, --directory=dir Changes the directory before executing the Makefile.
-f file, --file=file, --Makefile=FILE Uses a specific file as a Makefile.
-i, --ignore-errors Ignores all errors in commands.
-I dir, --include-dir=dir Specifies a directory to search for the specified Makefile.
-j [jobs], --jobs[=jobs] Specifies the number of jobs to run simultaneously.
-k, --keep-going Continues running make for as long as possible after getting an error.
-l [load], --load-average[=load] Specifies that no new task should be started if other tasks are in the queue.
-n, --dry-run, --just-print, --recon Prints expected output without executing make.
-o file, --old-file=file, --assume-old=file Ensures that make does not remake the file even if it is older than the dependencies.
-p, --print-data-base Prints the database produced after reading the Makefile.
-q, --question Activates the Question mode, in which make doesn't run any commands but returns an exit status zero if the target is already compiled.
-r, --no-builtin-rules Eliminates the built-in implicit rules.
-s, --silent, --quiet Restricts printing the commands as they are executed.
-S, --no-keep-going, --stop Stops "-k, --keep-going" command.
-t, --touch Touches files instead of running the commands.
--trace Traces each target's disposition.
-W file, --what-if=file, --new-file=file, --assume-new=file Ignores the fact that the target file has been modified.
--warn-undefined-variables Warns that an unknown variable is referenced.
To make a program file:
Change to the root directory.
Make a directory called the same as the program to be made.
Extract or copy all the files needed into that new directory.
Run the command
gcc filename1.c filename2.c
To check if an executable file has been made:
Change cd to the directory which holds the files from which the target executable was made.
Run the list command to show all files in that directory.
The filename of the executable will be the one coloured green.
To run the made file in the current directory:
./filename
To make a program with Make and Makefiles instead of using the compiler:
Change cd to the root directory.
Make a directory named after the program to be made.
Save a blank text document called makefile into that new directory.
Type the makefile sytax into the makefile like this -
target: dependencies
commands
Change target to the name of the target program to be made -
programname: dependencies
commands
change dependencies to a list of the object .o files which are to make up the program.
programname: main.o text.o
commands
Press tab and type the gcc compiler like this.
gcc main.o text.o
programname: main.o text.o
gcc main.o text.o
Type the -o flag and name the target like this
programname: main.o text.o
gcc main.o text.o -o programname
4. Add the -o flag and name the target my_app.
Makefile -o Flag
After writing the first rule, the Makefile looks like this:
my_app: main.o text.o
gcc main.o text.o -o my_app
Makefile With the First Rule Completed
Next, instruct the Makefile on how to create main.o:
1. Set main.o as the target.
2. Type in main.c as the dependency. main.c serves to create and update main.o.
3. Write the following command to update main.o every time main.c changes:
gcc -c main.c
4. Add the -c flag to instruct the Makefile not to create a new executable but only to read the code and compile the object file.
main.o: main.c
gcc -c main.c
Makefile for Object File main.c
To create text.o, set that file as the target, and add both text.c and text.h as dependencies. However, the gcc command only compiles the text.c file, since headers are never compiled:
text.o: text.c text.h
gcc -c text.c
Makefile for Object File text.c
Save the Makefile and type make in the terminal.
make Command Terminal Output
The make command created two object files (main.o and text.o) and the executable (my_app).
To verify that make created new files, run ls again:
make and ls Commands Terminal Output
The terminal shows that running the command created my_app. To run the my_app file, type:
./my_app
Executing my_app Terminal Output
Update the Program
When one source file is changed, make only updates object files depending on that source file. For instance, to change the text displayed when running the my_app from "Learn about Makefiles" to "Where am I?":
1. Open text.c in the text editor:
Changing the text.c Message
2. Change the text to "Where am I?":
Changed the text.c File Message
3. Save the file, open the terminal, and run make:
Make Command After the Changes Terminal Output
The make command detected changes in text.c and recompiled only that file.
To verify the change, run the executable:
./my_app
ls Command to Verify Changes
Compile All Files
To compile all files and not only the changed files, use -B or --always-make options.
For example, to change the text in the text.c file back to "Learn about Makefiles" and save the file, enter:
make -B
make -B Terminal Output
The output shows that make compiled all the files in the folder, even the ones that haven't been changed.
Clean Object Files
When a user runs make for the first time, the command creates object files and the executable. Therefore, to declutter the source folder and clean object files, add the clean function to the Makefile:
clean:
rm *.o my_app
Makefile and Clean Command
The command consists of:
The clean target with no dependencies - the target is always considered outdated and always executed.
The rm command - removes specified objects.
The *.o part - matches files with the o extension and cleans object files and my_app.
To clean object files, run:
make clean
make clean and ls Terminal Output
After running ls again, the terminal shows that the object files and my_app have been removed.
To download a package of sourcecode from the Github software repository, the git program can be used. Git does not come with the installation disk of Ubuntu system.
To install git:
sudo apt-get update
sudo apt-get install git
To download the source code of a package:
Find the package on the internet.
Copy the url address of that code.
Past the url after the wget command.
wget packagepath
wget https://github.com/packname/packname.git
The code will usually be downloaded to the home directory.
To extract the files from a downloaded package of source code, run tar or unzip:
tar packagename.tar.gz
or unzip packagename.zip
To show a list of the files in the package:
Change cd to the directory holding the package.
Run the ls command.
Note the name of the configuration script file.
To install software from source code:
Change cd to the directory holding the software package.
Run the make and install commands in terminal.
$ make
$ sudo make install
Run the list command to show the name of the configure file.
ls
Run the configuration script.
./configure
To allow permit the source code files to be installed into a directory:
cp pkgname /usr/local/bin/
chmod +x /usr/local/binpkgname
https://www.ubuntupit.com
Some packages install into a directory called /opt . That directory may have to be made.
To make a directory:
mkdir
eg mkdir /home/foldername/directoryname
Change the path and folder names as needed.
If a public key is required and available it is automatically downloaded and registered.
Remote repositories are internet servers full of software packages.
To show the local list of remote software repositories:
gedit /etc/apt/sources.list
The addresses of source code repositories begin with deb-src
deb-src http://security.ubuntu.com/ubuntu jammy-security universe
A # hash before the url address means that the repository is not in use.
To allow a repository to be used:
Delete the # mark, save the sources.list file and update apt-get
sudo apt-get update
Write - The write command in Linux sends a message from one user to another. It copies lines from the terminal of one user to that of another. The other user can reply using the write command.
When the sender sends a message, the receiver sees a messagefrom line like this in terminal:
Message from username@hostname on your tty at hh:mm ...
followed by the typed message.
The sender ends the message by typing and end of file character.
The receiver sees EOF at the end of the message.
When the sender sends a message, every user who is logged in to the terminal will see a popup message. The popup lets other users reply.
To show write usage:
joe@postbox22r:~$ write
usage: write user [tty]
Tty is the name of the terminal where the user is logged in.
eg write username tty7
where username is using terminal 7.
TTY stands for telytypewriter.
To show the name of this terminal you are using:
joe@postbox22r:~$ tty
/dev/pts/1
joe@postbox22r:~$
Using terminal t, tty1
To find the name of the terminal being used by a recipient, ask the recipient to run the tty command on his computer.
username@username-ID is on terminal /dev/pts/0
username@username-Inspiron-518 is on terminal /dev/pts/1
joe@postbox22r is on /dev/pts/4
To list the active TTY devices:
cat /proc/tty/drivers
joe@postbox22r:~$ cat /proc/tty/drivers
/dev/tty /dev/tty 5 0 system:/dev/tty
/dev/console /dev/console 5 1 system:console
/dev/ptmx /dev/ptmx 5 2 system
/dev/vc/0 /dev/vc/0 4 0 system:vtmaster
ttyprintk /dev/ttyprintk 5 3 console
max310x /dev/ttyMAX 204 209-224 serial
serial /dev/ttyS 4 64-111 serial
pty_slave /dev/pts 136 0-1048575 pty:slave
pty_master /dev/ptm 128 0-1048575 pty:master
unknown /dev/tty 4 1-63 console
joe@postbox22r:~$
That is what the drivers file shows. Widen the screen to see the table.
The active computer systems are shown in the far right column. They are 1 and 2. As the sender is 1, the recipient must be 2 on this small network. So the recipient is on tty2
joe@postbox22r:~$ write username ttyusername-ID
write: username is not logged in on ttyusername-ID
joe@postbox22r:~$
To write and send a message:
joe@postbox22r:~$ write username tty2
write: username is not logged in on tty2
or
joe@postbox22r:~$
joe@postbox22r:~$ write username
write: username is not logged in
or
joe@postbox22r:~$ write username [username-ID]
write: username is not logged in on [username-ID]
joe@postbox22r:~$
or
joe@postbox22r:~$ write username@username-ID
write: username@username-ID is not logged in
joe@postbox22r:~$
username is logged in on the other computer with Terminal open. So there is a network or address error.
or
joe@postbox22r:~$ write username7@postbox22
write: username7@postbox22 is not logged in
joe@postbox22r:~$
To write a test message to self:
joe@postbox22r:~$ write name
Hi name,
this is a test message using the write command.
Do you read it?
eof
Press ctrl-d to return to the terminal command prompt.
To end and send the message, type eof then press ctrl-d.
To toggle write messaging off:
mesg no
No more messages will be received.
To toggle messaging back on again:
mesg y
joe@postbox22r:~$ mesg n
joe@postbox22r:~$ mesg y
To show if messaging is on or off:
joe@postbox22r:~$ mesg
is y
joe@postbox22r:~$
To ask a question or ask the recipient to reply, end the message with o
for over instead of eof.
To say that the message does not need a reply, end it with oo
for over and out.
When username tries to write to name, the same message shows about the recipient nt being connected. It must be a network error.
A serial S communications port is named like ttyS2 or a USB port like ttyUSB3.
To write and send a message to all users logged in to the terminal, use the wall command.
wall
joe@postbox22r:~$ wall
The system will be down at 2pm for changes.
joe@postbox22r:~$
Press ctrl-d to deliver message.
Nobody received the message.
To show all users who are logged in:
who
joe@postbox22r:~$ who
name tty7 2022-06-17 16:32 (:0)
joe@postbox22r:~$
name is the only one logged in on this computer but username is logged in on the other computer. The who command run on each computer says each of them is on tty7.
Write can start a message with a command
like
write root pts/2
Type message here.
and send the message by typying ctrl-d.
joe@postbox22r:~$ write root pts/2
write: root is not logged in on pts/2
joe@postbox22r:~$ write username pts/2
write: username is not logged in on pts/2
joe@postbox22r:~$
# The following line is added to set a FQDN
127.0.0.1 www.postbox22.com postbox22
name@postbox22:~$ cat /var/run/utmp
~~~reboot4.8.0-36-generic��b��5~~~runlevel4.8.0-36-generic/��b�
�tty1tty1LOGIN�1��bB �tty7:0name:0K��b��name@postbox22:~$
name@postbox22:~$
To talk to another user on the same computer:
The sender runs a command like this
talk recipientname recipientttyname
eg talk user /dev/pts/6
That is the login name of the person.
To talk to a user of another computer:
talk recipient@hostname recipientttyname
eg talk user@postbox22 /dev/pts/66
or talk user@hostname.com /dev/pts/14
That is the login name of the recipient person followed by @ and the hostname of his computer.
Talk connects to the computer of the recipient and leaves a message like this
talk: connection requested by your_name@your_machine.
The recipient responds and sends a message to the sender.
talk sendername@sendercomputer
Here the first user, the one who started the talk, is called the sender and the second the receiver.
To respond to a talk message from another user:
See an auto message like
talk: respond with: talk your_name@your_machine
talk sendername@senderhostname
eg talk john@hostname
Once both users have their terminal screens connected:
talk username
eg talk user
or talk username@hostname
talk user@postbox22
To reprint and refresh text on the screen:
ctrl+l
To scroll the screen, press esc-p then esc-n
or ctrl-p then ctrl-n
To close the Talk terminal:
ctrl-c
Wall is installed with Ubuntu.
To run wall:
wall option filename message
username@hostname-ID:~$ wall
^C
username@hostname-ID:~$
wall -- send a message to everybody’s terminal.
wall [-n] [ message ]
Wall sends a message to everybody logged in with their mesg(1) permission set to yes.
Tag option
-n changes the normal banner printed by wall to a remote broadcast message.
Wall ignores the time zone and prints the time from the local system.
username@hostname-ID:~$ wall
Notice to all local users.
.
Press ctrl-d to deliver.
username@hostname-ID:~$
username@hostname-ID:~$ tel
The program 'tel' is currently not installed. You can install it by typing:
sudo apt install orville-write
That write program is for writing, sending and receiving messages, telexes or twits to other people using the program when they are on line.
Download it from https://unixpapa.com/write.html
username@hostname-ID:~$ orville-write
The program 'orville-write' is currently not installed. You can install it by typing:
sudo apt install orville-write
username@hostname-ID:~$
Maximum Transmission Unit MTU
https://linuxhint.com/how-to-change-mtu-size-in-linux/
The MTU size of an Ethernet interface is 1500 bytes by default.
MTU is the maximum size of the packet of data that can be transmitted from a network interface. All the devices including servers and switches/routers involved in communication should have the same MTU size. Large MTU size has less overhead associated with it while the smaller MTU has less delay.
To view the current mtu size:
ifconfig
Look for MTU:1500 or MTU whatever size.
username@hostname-ID:~$ ifconfig
enp5s3 Link encap:Ethernet HWaddr 00:0f:b5:fd:af:f4
inet addr:192.168.1.102 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::b813:3399:2650:ae9a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:40036 errors:0 dropped:0 overruns:0 frame:0
TX packets:39509 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32644020 (32.6 MB) TX bytes:6795287 (6.7 MB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:20415 errors:0 dropped:0 overruns:0 frame:0
TX packets:20415 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:3298878 (3.2 MB) TX bytes:3298878 (3.2 MB)
username@hostname-ID:~$
Here MTU:65536 is the packet size for the lo local interface and MTA:1500 is on default for interface enp5s3.
or run
ip a
username@hostname-ID:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp5s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0f:b5:fd:af:f4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.102/24 brd 192.168.1.255 scope global dynamic enp5s3
valid_lft 83705sec preferred_lft 83705sec
inet6 fe80::b813:3399:2650:ae9a/64 scope link
valid_lft forever preferred_lft forever
username@hostname-ID:~$
To change the MTU size temporarily:
ifconfig interfacename mtu size up
eg sudo ifconfig enp5s3 1600 up
username@hostname-ID:~$ sudo ifconfig enp5s3 mtu 1600 up
username@hostname-ID:~$
username@hostname-ID:~$ ifconfig
enp5s3 Link encap:Ethernet HWaddr 00:0f:b5:fd:af:f4
inet addr:0.0.6.64 Bcast:255.255.255.255 Mask:0.0.0.0
inet6 addr: fe80::b813:3399:2650:ae9a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1600
To change and fix the mtu size so that it stays after the computer is rebooted:
For a static IP address, change the size in the file called /etc/network/interfaces.
$ sudo nano /etc/network/interfaces
Append the below line in the file:
post-up /sbin/ifconfig mtu
Make sure to replace with the actual interface name and with the MTU size you want to set on the network interface.
For instance, to change the MTU size of an interface named ens33 to 1300 bytes, the command would be:
post-up /sbin/ifconfig ens33 mtu 1300 up
Once you have configured the file, save, and close it.
Now restart the networking services using the following command in Terminal:
$ sudo service networking restart
Also, bring up the interface using the following command:
$ sudo ifup
Make sure to replace the with the actual network interface on your system e.g. ens33, eth0, eth1, etc.
In our case, it would be:
$ sudo ifup ens33
Now issue the following command in Terminal to verify if the MTU size has changed successfully.
$ ip a
This change will be kept persistent and will not be affected even after a reboot.
For a dynamic IP address, the MTU size is set automatically by DHCP. So configure the DHCP file called /etc/dhcp/dhcpclient.conf.
username@hostname-ID:~$ sudo gedit /etc/dhcp/dhclient.conf
Look in the file for a line like this.
#send dhcp-lease-time 3600;
Then add the following lines below the “send host-name = gethostname(); line:
default interface-mtu ;
supersede interface-mtu ;
For instance, to set the MTU size to 1400, we will add:
default interface-mtu 1400;
supersede interface-mtu 1400;
If you have multiple interfaces and you want to change the MTU size of just one interface, then enclose it in the braces as follows:
interface "interface_name" {
default interface-mtu ;
supersede interface-mtu ;
Once you have configured the file, save, and close it.
Now restart the networking service using the following command in Terminal:
$ sudo service networking restart
Also, bring up the interface using the following command:
$ sudo ifup
Make sure to replace the with the actual network interface on your system e.g ens33, eth0, eth1, etc.
In our case, it would be:
$ sudo ifup ens33
Now issue the following command in Terminal to verify if the MTU size has changed successfully.
$ sudo ifconfig | grep mtu
From the output, you can see the MTU size has been changed to 1400.
To write long file names:
Linux likes file and directory names which do not have an spaces in them. So do not type spaces in a file name. Type an underline instead of a space; like this very_long_file_name .
If a file or directory name does have spaces in it, tell Linux by typing the name within quotes, like this:
"very long file name" .
So commands look like these:
cd "very long file name"
cd 'very long file name'
touch filenameone
gedit filenameone
cat "file name with spaces"
mkdir "new directory"
mkdir new_directory
mkdir newdirectory
Avoid using slashes within a file or directory name.
To find and list the files in a directory which is on a partition of a separate hard drive mounted on the same computer:
user:~$ cd /
user:/$ ls
bin dev initrd.img lost+found opt run srv usr
boot etc lib media proc sbin sys var
cdrom home lib64 mnt root snap tmp vmlinuz
user:/$ ls media
file floppy floppy0 Read-only system user tom
user:/$ ls media/user
101 GB part
user:/$ ls media/user/"101 GB part"/
home lost+found
user:/$ ls media/user/"101 GB part"/home/
user
user:/$ ls media/user/"101 GB part"/home/user/
Documents Downloads Programs Scripts
user:/$ ls media/user/"101 GB part"/home/user/Scripts/
2at1.sh calc.sh login.sh propert.sh shdir.sh
backscript delete.sh message.sh router.sh sum678.sh
user:/$
Linux will not list a partition until it is mounted.
To show who is logged in:
username@hostname-ID:~$ who
mick tty7 2023-12-12 08:33 (:0)
username@hostname-ID:~$
To show the names of users:
username@hostname-ID:~$ sudo lslogins -u
[sudo] password for mick:
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 129 0 1 root
1000 mick 67 0 0 Dec12/08:33 mick,,,
username@hostname-ID:~$
To show information about a user:
username@hostname-ID:~$ sudo lslogins mick
Username: mick
UID: 1000
Gecos field: mick,,,
Home directory: /home/mick
Shell: /bin/bash
No login: no
Password is locked: no
Password not required: no
Login by password disabled: no
Primary group: mick
GID: 1000
Supplementary groups: sambashare,adm,cdrom,sudo,dip,plugdev,lpadmin
Supplementary group IDs: 128,4,24,27,30,46,113
Last login: Dec12/08:33
Last terminal: tty7
Last hostname: :0
Hushed: no
Password expiration warn interval: 7
Password changed: Dec07/11:00
Maximum change time: 99999
Running processes: 67
Last logs:
username@hostname-ID:~$
To show what permission a user has to use files:
username@hostname-ID:~$ sudo ls -la /home/mick/
total 224
drwxr-xr-x 27 mick mick 4096 Dec 12 08:34 .
drwxr-xr-x 3 root root 4096 Oct 4 23:24 ..
-rw-rw-r-- 1 mick mick 24 Dec 11 19:47 .aspell.en.prepl
-rw------- 1 mick mick 11177 Dec 12 13:12 .bash_history
-rw-r--r-- 1 mick mick 220 Oct 4 23:24 .bash_logout
-rw-r--r-- 1 mick mick 3771 Oct 4 23:24 .bashrc
drwx------ 26 mick mick 4096 Oct 30 17:26 .cache
drwx------ 3 mick mick 4096 Feb 12 2016 .compiz
drwx------ 30 mick mick 4096 Dec 8 20:09 .config
drwx------ 3 root root 4096 Oct 10 10:44 .dbus
drwxrwxr-x 6 mick mick 4096 Oct 22 15:30 .dc
drwxr-xr-x 2 mick mick 4096 Dec 12 15:33 Desktop
-rw-r--r-- 1 mick mick 25 Oct 4 23:58 .dmrc
drwxr-xr-x 2 mick mick 4096 Dec 3 08:38 Documents
drwxr-xr-x 2 mick mick 4096 Oct 21 18:11 Downloads
-rw-r--r-- 1 mick mick 8980 Oct 4 23:24 examples.desktop
drwx------ 3 mick mick 4096 Dec 12 08:38 .gconf
To find the ip address of your default gateway:
netstat
username@hostname-ID:~$ sudo netstat -nr
[sudo] password for user:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
username@hostname-ID:~$
The gateway is 192.168.1.1 for this computer and for another computer on the network. The gateway for a third computer is 192.168.0.1
To set up Network File Sharing for Linux, install NFS.
To install NFS on the computer which is to be the server for file sharing:
username@websitename:~$ sudo apt-get install nfs-kernel-server nfs-common portmap
[sudo] password for name:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'rpcbind' instead of 'portmap'
The following packages were automatically installed and are no longer required:
libgsasl7 libkyotocabinet16v5 libmailutils4 libntlm0 mailutils-common
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
keyutils libnfsidmap2 libtirpc1
Suggested packages:
open-iscsi watchdog
The following NEW packages will be installed:
keyutils libnfsidmap2 libtirpc1 nfs-common nfs-kernel-server rpcbind
0 to upgrade, 6 to newly install, 0 to remove and 0 not to upgrade.
Need to get 468 kB of archives.
After this operation, 1,874 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://au.archive.ubuntu.com/ubuntu xenial/main amd64 libnfsidmap2 amd64 0.25-5 [32.2 kB]
Get:2 http://au.archive.ubuntu.com/ubuntu xenial/main amd64 libtirpc1 amd64 0.2.5-1 [75.6 kB]
Get:3 http://au.archive.ubuntu.com/ubuntu xenial/main amd64 keyutils amd64 1.5.9-8ubuntu1 [47.1 kB]
Get:4 http://au.archive.ubuntu.com/ubuntu xenial/main amd64 rpcbind amd64 0.2.3-0.2 [40.3 kB]
Get:5 http://au.archive.ubuntu.com/ubuntu xenial/main amd64 nfs-common amd64 1:1.2.8-9ubuntu12 [185 kB]
Get:6 http://au.archive.ubuntu.com/ubuntu xenial/main amd64 nfs-kernel-server amd64 1:1.2.8-9ubuntu12 [88.0 kB]
Fetched 468 kB in 0s (716 kB/s)
Selecting previously unselected package libnfsidmap2:amd64.
(Reading database ... 175633 files and directories currently installed.)
Preparing to unpack .../libnfsidmap2_0.25-5_amd64.deb ...
Unpacking libnfsidmap2:amd64 (0.25-5) ...
Selecting previously unselected package libtirpc1:amd64.
Preparing to unpack .../libtirpc1_0.2.5-1_amd64.deb ...
Unpacking libtirpc1:amd64 (0.2.5-1) ...
Selecting previously unselected package keyutils.
Preparing to unpack .../keyutils_1.5.9-8ubuntu1_amd64.deb ...
Unpacking keyutils (1.5.9-8ubuntu1) ...
Selecting previously unselected package rpcbind.
Preparing to unpack .../rpcbind_0.2.3-0.2_amd64.deb ...
Unpacking rpcbind (0.2.3-0.2) ...
Selecting previously unselected package nfs-common.
Preparing to unpack .../nfs-common_1%3a1.2.8-9ubuntu12_amd64.deb ...
Unpacking nfs-common (1:1.2.8-9ubuntu12) ...
Selecting previously unselected package nfs-kernel-server.
Preparing to unpack .../nfs-kernel-server_1%3a1.2.8-9ubuntu12_amd64.deb ...
Unpacking nfs-kernel-server (1:1.2.8-9ubuntu12) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
ureadahead will be reprofiled on next reboot
Setting up libnfsidmap2:amd64 (0.25-5) ...
Setting up libtirpc1:amd64 (0.2.5-1) ...
Setting up keyutils (1.5.9-8ubuntu1) ...
Setting up rpcbind (0.2.3-0.2) ...
Setting up nfs-common (1:1.2.8-9ubuntu12) ...
Creating config file /etc/idmapd.conf with new version
Creating config file /etc/default/nfs-common with new version
Adding system user `statd' (UID 124) ...
Adding new user `statd' (UID 124) with group `nogroup' ...
Not creating home directory `/var/lib/nfs'.
nfs-utils.service is a disabled or a static unit, not starting it.
Setting up nfs-kernel-server (1:1.2.8-9ubuntu12) ...
Creating config file /etc/exports with new version
Creating config file /etc/default/nfs-kernel-server with new version
Processing triggers for libc-bin (2.23-0ubuntu5) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
username@websitename:~$
To let other computers on the local network share a folder on this NFS server:
Recongigure the portmap.
dpkg-reconfigure portmap
username@websitename:~$ sudo dpkg-reconfigure portmap
dpkg-query: package 'portmap' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.
/usr/sbin/dpkg-reconfigure: portmap is not installed
username@websitename:~$
Here you should be able to select no on the menu.
Restart portmap to keep changes.
sudo /etc/init.d/portmap restart
username@websitename:~$ sudo /etc/init.d/portmap restart
sudo: /etc/init.d/portmap: command not found
username@websitename:~$
Make a new directory in which to store files for sharing.
This command will make a directory which the clients can see.
mkdir -p /export/postbox22fs/
username@websitename:~$ sudo mkdir -p /export/postbox22fs/
username@websitename:~$
To mount the shared directory automatically whenever the server boots up:
Edit the fstab file.
sudo gedit /etc/fstab
username@websitename:~$ sudo gedit /etc/exports
[sudo] password for name:
Edit the file as shown in nfsharing.txt file from WikiHow.com.
# /postbox22fs is for NFS file sharing
/export/postbox22fs
127.0.0.0/24 (rw,no_root_squash,async)
127.0.0.1/24 (rw,no_root_squash,async)
127.0.0.2/24 (rw,no_root_squash,async)
127.0.0.1/8 (rw,no_root_squash,async)
username@websitename:~$ sudo /etc/init.d/nfs-kernel-server restart
[ ok ] Restarting nfs-kernel-server (via systemctl): nfs-kernel-server.service.
username@websitename:~$
To connect the client computers:
Open the terminal in a client computer.
Install the NFS client files.
sudo apt-get install portmap nfs-common
The portmap software package is missing or obsoleted. So the NFS package is broken, hence the error in installing it, and the software for clients is missing.
Find portmap before continuing.
Make the directory in which shared files will be mounted on the client computer.
Continued in nfsharing.txt.
To map the network and scan ports:
nmap
https://nmap.org/book/man.html
Nmap must be kept up to date to be reliable.
To install nmap:
pete@pete-ID:~$ nmap
Command 'nmap' not found, but can be installed with:
sudo snap install nmap # version 7.94, or
sudo apt install nmap # version 7.91+dfsg1+really7.80+dfsg1-2ubuntu0.1
See 'snap info nmap' for additional versions.
pete@pete-ID:~$
To explore and map a network of computers:
nmap scantype options targetname
The program called nmcli is a network manager.
To display the IPv4 and IPv6 addresses on all available network devices DNS server IP addresses:
nmcli ?
To show the nmcli help menu:
nmcli h
To show the general status and operations of Network Manager:
nmcli g
name@postbox22:~$ nmcli g
STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled
name@postbox22:~$
To check that the overall network control is enabled:
nmcli n
name@postbox22:~$ nmcli n
enabled
name@postbox22:~$
To show id wifi radio and wan are enabled:
name@postbox22:~$ nmcli r
WIFI-HW WIFI WWAN-HW WWAN
enabled enabled enabled enabled
name@postbox22:~$
To show the network connections of Network Manager:
nmcli c
name@postbox22:~$ nmcli c
NAME UUID TYPE DEVICE
Ethernet connection 1 d215b5d6-5ecd-40a3-9a9f-d9ee917fb615 802-3-ethernet enp6s0
Ifupdown (enp6s0) eaaee6bd-545d-d1eb-d409-c52861fd7d4d 802-3-ethernet --
VPN connection 1 4e1a43a6-6e0e-41fd-9b32-b83a1d7e5963 vpn --
Wired connection 1 85e2f7ee-9836-33b7-b50e-761b1c4d5702 802-3-ethernet --
enp6s0 ad0eb91e-5780-46b4-8e70-75f820b916a8 802-3-ethernet --
name@postbox22:~$
or nmcli con show
or nmcli connection
To show what devices are being managed by Network Manager:
nmcli d
name@postbox22:~$ nmcli d
DEVICE TYPE STATE CONNECTION
enp6s0 ethernet connected Ethernet connection 1
lo loopback unmanaged --
name@postbox22:~
or nmcli dev status
To monitor changes of connections in Network Manager, run this command, click the two-arrows icon on the desktop, change connections and watch the output.
nmcli m
name@postbox22:~$ nmcli m
enp6s0: deactivating
Connectivity is now 'none'
There's no primary connection
enp6s0: using connection 'Ethernet connection 1'
enp6s0: connecting (getting IP configuration)
Connectivity is now 'full'
'Ethernet connection 1' is now the primary connection
enp6s0: connected
enp6s0: deactivating
enp6s0: disconnected
enp6s0: connected
enp6s0: using connection 'enp6s0'
Connectivity is now 'full'
'enp6s0' is now the primary connection
enp6s0: deactivating
enp6s0: disconnected
Connectivity is now 'none'
There's no primary connection
Connectivity is now 'full'
'Ifupdown (enp6s0)' is now the primary connection
enp6s0: connected
enp6s0: using connection 'Ifupdown (enp6s0)'
enp6s0: deactivating
Connectivity is now 'none'
There's no primary connection
enp6s0: connecting (getting IP configuration)
enp6s0: using connection 'Ethernet connection 1'
Connectivity is now 'full'
'Ethernet connection 1' is now the primary connection
enp6s0: connected
enp6s0: deactivating
Connectivity is now 'none'
There's no primary connection
enp6s0: connecting (getting IP configuration)
enp6s0: using connection 'Ethernet connection 1'
Connectivity is now 'full'
'Ethernet connection 1' is now the primary connection
enp6s0: connected
^C
Error: nmcli terminated by signal Interrupt (2)
name@postbox22:~$
To cancel the monitor press ctrl-c .
To show the status of the network interface device:
nmcli d
DEVICE TYPE STATE CONNECTION
enp6s0 ethernet connected Ethernet connection 1
lo loopback unmanaged --
name@postbox22:~$
To activate a connection:
nmcli -p con up id "Wired connection 1"
To disconnect the network interface:
nmcli dev disconnect enp0s3
To activate connect the network interface automatically, set the autoconnect property of the network interface to true.
To activate the network interface manually with the connect parameter:
nmcli dev connect interfacename
eg nmcli dev connect enp0s3
Network connections are saved in files. By default, these files are not monitored by NetworkManager. If we change any of these files, the changes are not applied instantly. We need to reload the files.
To reload the network configuration files and keep the latest changes to them:
nmcli con reload
name@postbox22:~$ nmcli con reload
Error: failed to reload connections: Rejected send message, 4 matched rules; type="method_call", sender=":1.142" (uid=1000 pid=5368 comm="nmcli con reload ") interface="org.freedesktop.NetworkManager.Settings" member="ReloadConnections" error name="(unset)" requested_reply="0" destination=":1.8" (uid=0 pid=988 comm="/usr/sbin/NetworkManager --no-daemon ").
name@postbox22:~$
Changes to network and interface files have been made by other programs such as gedit direct, ifconfig, ifupdown and IP. One program may not see what the another program has changed.
To make create a new Ethernet connection and assign a static IP address to it:
name@postbox22:~$ nmcli con add con-name eth0 type ethernet ifname eth0 ipv4.method manual ipv4.address 192.168.0.10
Error: Argument '--' was expected, but 'ipv4.method' provided.
name@postbox22:~$
Here a new connection was not made because of a sytax error between different versions of nmcli. So that connection cannot be deleted as it is not there.
To delete this new connection just added:
nmcli con del "eth0"
name@postbox22:~$ nmcli con del "eth0"
Error: unknown connection 'eth0'
Error: cannot delete unknown connection(s): 'eth0'.
name@postbox22:~$
https://bytexd.com/how-to-use-the-nmcli-command-to-manage-networkmanager/
To check the status of interface devices:
nmcli dev status
name@postbox22:~$ nmcli dev status
DEVICE TYPE STATE CONNECTION
enp6s0 ethernet connected Ethernet connection 1
lo loopback unmanaged --
name@postbox22:~$
To check active connections on devices:
nmcli connection
name@postbox22:~$ nmcli connection
NAME UUID TYPE DEVICE
Ethernet connection 1 d215b5d6-5ecd-40a3-9a9f-d9ee917fb615 802-3-ethernet enp6s0
Ifupdown (enp6s0) eaaee6bd-545d-d1eb-d409-c52861fd7d4d 802-3-ethernet --
VPN connection 1 4e1a43a6-6e0e-41fd-9b32-b83a1d7e5963 vpn --
Wired connection 1 85e2f7ee-9836-33b7-b50e-761b1c4d5702 802-3-ethernet --
enp6s0 ad0eb91e-5780-46b4-8e70-75f820b916a8 802-3-ethernet --
name@postbox22:~$
Widen this page to see the table.
The UUID is the number of connection, its universally unique identifier.
install - The install command does not install any software package. It is for copying files and setting attributes like file ownership.
To install packages, use the package manager which comes with the Linux distribution, like apt, apt-get, dpkg, dnf, yum or zypper.
To use the install command instead of the cp command to copy files:
install filename /directory
Here a file called raid is copied from one directory to another and renamed as raid test.
tom@tom-id:~$ install ~/Desktop/raid ~/Pictures/raidtest
tom@tom-id:~$ ls ~/Pictures/raidtest
/home/tom/Pictures/raidtest
tom@tom-id:~$ ls ~/Pictures
raidtest Screenshots
tom@tom-id:~$
The list ls command checks that the copy has been made.
By default, the install command keeps the original file permissions and ownership but updates the timestamps with the time the file is copied.
To keep the original time stamp, use the -p option or flag.
install -p filename directoryname
To make a new directory, use the -d option:
install -d directoryname
The tilde ~ means /home directory.
tom@tom-id:~$ install -d ~/Desktop/testd
tom@tom-id:~$ ls ~/Desktop/testd
tom@tom-id:~$
To copy files into a new directory:
Here the file is called bread.
tom@tom-id:~$ install ~/Desktop/bread ~/Desktop/testd/breadtest
tom@tom-id:~$ ls ~/Desktop/testd/
breadtest
tom@tom-id:~$
To copy a file from the current working directory . into a subdirectory:
tom@tom-id:~/Desktop$ install bread ~/Desktop/testd/bread2
tom@tom-id:~/Desktop$ ls ./testd/
bread2 breadtest
tom@tom-id:~/Desktop$
That ./ means current working directory.
Instead of the install command, use the chmod command to change the permission or ownerhsip of a file. Cchmod changes the permissions of files or directories.
To show the permissions and Access Control List ACL of files, run the command getfacl :
getfacl filename.txt
Here the one file is called bread.
tom@tom-id:~/Desktop$ getfacl ~/Desktop/bread
getfacl: Removing leading '/' from absolute path names
# file: home/tom/Desktop/bread
# owner: tom
# group: tom
user::rw-
group::rw-
other::r--
tom@tom-id:~/Desktop$
There user named tom has permission to rw- read and write to files but not execute x them. So does anybody in his group. Other users have r read-only permission.
To show the ACL list only of all files in a directory:
$ getfacl -d ~/Desktop/*
The command setfacl is used to set change modify the permissions of files on the access control list ACL. It changes who can access the files.
The -m modify and -M --modify-file)options modify the ACL of a file or directory. ACL entries for this operation must include permissions.
setfacl -m u:username:rwx filename
Change to the directory which holds the file or files to be changed.tom@tom-id:~/Desktop$ setfacl -m u:tom:rwx mirrors24
Now that is done, check it with getfacl.
tom@tom-id:~/Desktop$ getfacl mirrors24
# file: mirrors24
# owner: tom
# group: tom
user::rw-
user:tom:rwx
group::rw-
mask::rwx
other::r--
tom@tom-id:~/Desktop$
tom@tom-id:~/Desktop$ getfacl ~/Desktop/testd/
getfacl: Removing leading '/' from absolute path names
# file: home/tom/Desktop/testd/
# owner: tom
# group: tom
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:tom:rw-
default:group::r-x
default:mask::rwx
default:other::r-x
tom@tom-id:~/Desktop$
There the user tom does not have by default permission to execute run files. So change wr- to wrx as shown below.
To set a default ACL entry on a directory, use the command setfacl -d -m u:username:rwx dirname
tom@tom-id:~/Desktop$ setfacl -d -m u:tom:rwx testd
tom@tom-id:~/Desktop$ setfacl -d -m u:tom:rwx ~/Desktop/testd
tom@tom-id:~/Desktop$ getfacl testd
# file: testd
# owner: tom
# group: tom
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:tom:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
tom@tom-id:~/Desktop$
Tom now has x permission again.
See chmod and
https://www.howtogeek.com/how-to-use-filesystem-acl-on-linux/
https://www.computerhope.com/unix/usetfacl.htm
To show the network mask of a device:
ifconf
harry@harry-ID:~$ ifconfig
enp1s2 Link encap:Ethernet HWaddr 00:18:4d:78:66:53
inet6 addr: fe80::8a17:826:91d4:a44/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:1007 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:180416 (180.4 KB)
enp1s5 Link encap:Ethernet HWaddr 00:1a:4d:21:ad:51
inet addr:192.168.1.107 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::e3fe:6612:a3b5:58c5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5764 errors:0 dropped:0 overruns:0 frame:0
TX packets:4549 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5389396 (5.3 MB) TX bytes:455328 (455.3 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1647 errors:0 dropped:0 overruns:0 frame:0
TX packets:1647 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:174489 (174.4 KB) TX bytes:174489 (174.4 KB)
harry@harry-ID:~$
To list modules inserted into the kernel:
harry@harry-ID:~$ lsmod
Module Size Used by
gpio_ich 16384 0
snd_hda_codec_realtek 86016 1
snd_hda_codec_generic 73728 1 snd_hda_codec_realtek
snd_hda_intel 36864 3
snd_hda_codec 135168 3 snd_hda_intel,snd_hda_codec_generic,snd_hda_codec_realtek
snd_hda_core 86016 4 snd_hda_intel,snd_hda_codec,snd_hda_codec_generic,snd_hda_codec_realtek
snd_hwdep 16384 1 snd_hda_codec
snd_pcm 110592 3 snd_hda_intel,snd_hda_codec,snd_hda_core
snd_seq_midi 16384 0
snd_seq_midi_event 16384 1 snd_seq_midi
usblp 20480 0
snd_rawmidi 32768 1 snd_seq_midi
snd_seq 69632 2 snd_seq_midi_event,snd_seq_midi
snd_seq_device 16384 3 snd_seq,snd_rawmidi,snd_seq_midi
snd_timer 32768 2 snd_seq,snd_pcm
snd 86016 16 snd_hda_intel,snd_hwdep,snd_seq,snd_hda_codec,snd_timer,snd_rawmidi,snd_hda_codec_generic,snd_seq_device,snd_hda_codec_realtek,snd_pcm
soundcore 16384 1 snd
input_leds 16384 0
serio_raw 16384 0
lpc_ich 24576 0
mac_hid 16384 0
binfmt_misc 20480 1
parport_pc 32768 1
ppdev 20480 0
lp 20480 0
parport 49152 3 lp,parport_pc,ppdev
autofs4 40960 2
uas 24576 0
usb_storage 73728 1 uas
i915 1310720 3
psmouse 139264 0
8139too 36864 0
video 40960 1 i915
8139cp 28672 0
r8169 81920 0
pata_acpi 16384 0
i2c_algo_bit 16384 1 i915
mii 16384 3 r8169,8139cp,8139too
drm_kms_helper 167936 1 i915
syscopyarea 16384 1 drm_kms_helper
sysfillrect 16384 1 drm_kms_helper
floppy 73728 0
sysimgblt 16384 1 drm_kms_helper
fb_sys_fops 16384 1 drm_kms_helper
fjes 28672 0
drm 368640 5 i915,drm_kms_helper
harry@harry-ID:~$
To show interface names and link availablility:
harry@harry-ID:~$ dmesg
[ 4967.380633] [drm:i9xx_get_fifo_size] FIFO size - (0x00001d9c) A: 28
[ 4967.380635] [drm:intel_calculate_wm] FIFO entries required for mode: 27
[ 4967.380637] [drm:intel_calculate_wm] FIFO watermark level: -1
[ 4967.380639] [drm:i9xx_get_fifo_size] FIFO size - (0x00001d9c) B: 31
[ 4967.380641] [drm:i9xx_update_wm] FIFO watermarks - A: 8, B: 29
[ 4967.380643] [drm:intel_set_memory_cxsr] memory self-refresh is disabled
[ 4967.380645] [drm:i9xx_update_wm] self-refresh entries: 86
[ 4967.380648] [drm:i9xx_update_wm] Setting FIFO watermarks - A: 8, B: 29, C: 2, SR 9
[ 4967.380650] [drm:intel_set_memory_cxsr] memory self-refresh is enabled
[etc [ 5154.500697] [drm:intel_set_memory_cxsr] memory self-refresh is disabled
[ 5154.500699] [drm:i9xx_update_wm] self-refresh entries: 86
[ 5154.500701] [drm:i9xx_update_wm] Setting FIFO watermarks - A: 8, B: 29, C: 2, SR 9
[ 5154.500703] [drm:intel_set_memory_cxsr] memory self-refresh is enabled
harry@harry-ID:~$
To restart the network and bring an interface online:
harry@harry-ID:~$ /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.
harry@harry-ID:~$
see too staticip2.txt networkset.txt
Click two arrows icon on top menu of desktop and select Wired connection 1 to connect to the internet.
Setting a static IP address may cause an error message in Network gui program.
To fix the error when the two arrows menu on the desktop shows the message Ethernet Networks device not managed, edit the NetworkManager.cof file:
sudo gedit /etc/NetworkManager/NetworkManager.conf
In the last line of this configuration file, replace the managed=false to managed=true.
Save the file and exit the editor.
Restart the network with
sudo restart network-manager
See another error message but ignore it.
Restart the network.
Restart the computer.
Click the two arrows icon on the top menu of the desktop.
Select Wired connection 1.
Open the web browser and go to any website.
Other connections on the menu like eth0 or ifupdown eth0 do not connect to the internet. They connect to the local network for internal mail and write messaging.
To restart the network:
sudo restart network-manager
Check that the gateway setting for IPv4 in Network gui is on white, not orange or red.
When a setting is right, the field background turns white.
The Terminal command for Network-Manager is NetworkManager without a hyphen.
user@user-ID:~$ sudo NetworkManager
user@user-ID:~$
Systemctl error fix
There are two network management tools, NetworkManager and network. If both are configured, it will cause conflicts, and NetworkManager will clean up the routes when the network is disconnected. If some custom routes, which are not added to NetworkManager’s configuration file, the routes are cleaned up and need to be custom added on after the network is connected.
Solution.
1. Stop the networkmanager service
systemctl stop NetworkManager
systemctl disable NetworkManager
2. restart the network card, it is OK
systemctl restart network
systemctl status network
Systemctl is already installed.
or
systemctl stop NetworkManager
systemctl disable NetworkManager
service network restart
That will stop this error message from showing after the command
systemctl start network.service
Restarting network (via systemctl): Job for network.service failed because the control process exited with error code.
See “systemctl status network.service” and “journalctl -xe” for details.
To restart the NetworkManager service:
sudo systemctl unmask NetworkManager
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager
Now the NetworkManager is enabled, interface configurations can be done via the GUI or from the command line, using the nmcli command. The nmcli command runs NetworkManager, as it is called on the command line, but it is called Network-Manager in gui, with a hyphen.
To check if net-tools is installed, run this command:
nmcli -p
user@user-ID:~$ nmcli -p
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }
OPTIONS
-t[erse] etc
OBJECT
g[eneral] NetworkManager's general status and operations
n[etworking] overall networking control
r[adio] NetworkManager radio switches
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
a[gent] NetworkManager secret agent or polkit agent
m[onitor] monitor NetworkManager changes
user@user-ID:~$
So NetworkManager is with Net-tools.
To check if Network-Manager is active:
user@user-ID:~$ sudo systemctl status Network-Manager -l
[sudo] password for user:
● Network-Manager.service
Loaded: not-found (Reason: No such file or directo
Active: inactive (dead)
user@user-ID:~$
To check is systemd is installed:
user@user-ID:~$ systemd
Failed to create /user.slice/user-1000.slice/session-c2.scope/init.scope control group: Permission denied
Failed to allocate manager object: Permission denied
user@user-ID:~$
Yes it is installed.
Systemd-networkd is not for Ubuntu10. Network-Manager is only a gui and so is not needed.
To disable Network Manager in Ubuntu18 and enable systemd-networkd instead:
First, run the following set of commands to disable the NetworkManager:
Systemctl is already installed.
sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager
sudo systemctl mask NetworkManager
Do not run mask if you do not want Networked.
Next, start and enable the systemd-networkd service:
sudo systemctl unmask systemd-networkd.service
sudo systemctl enable systemd-networkd.service
sudo systemctl start systemd-networkd.service
Netplan is an utility developed by Canonical, the company behind Ubuntu. It provides a network configuration abstraction over the currently supported two “backend” system, (or “renderer” in Netplan terminology): networkd and NetworkManager. Using Netplan, both physical and virtual network interfaces are configured via yaml files which are translated to configurations compatible with the selected backend.
Add the interface configuration to the netplan config file (in the /etc/netplan directory):
user@user-ID:~$ ls /etc/netplan/
ls: cannot access '/etc/netplan/': No such file or directory
user@user-ID:~$
Netplan is not installed. Do not install it as it may conflict with ifupdown, ip, ifconfig, systemctl or systemd.
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
Apply the changes by running the following command:
sudo netplan apply
In the preceding example, we configured the enp0s3 interface to lease IP addresses from the DHCP Server. If you want to set static IP addresses, Click on the following link to learn how to configure static IP address with netplan.
Enable NetworkManager and Disable systemd networkd
Starting and enabling Ubuntu Network Manager can be done with the following steps (Which is not recommended in Ubuntu server).
First, stop the systemd-networkd service:
sudo systemctl disable systemd-networkd.service
sudo systemctl mask systemd-networkd.service
sudo systemctl stop systemd-networkd.service
Install NetworkManager on Ubuntu:
sudo apt-get install network-manager
Open the .yaml config file inside the /etc/netplan directory and replace the existing configuration with following:
network:
version: 2
renderer: NetworkManager
Netplan does not come with Ubuntu install disk. It is not installed.
user@user-ID:~$ netplan
The program 'netplan' is currently not installed. You can install it by typing:
sudo apt install netplan
You will have to enable the component called 'universe'
user@user-ID:~$
Generate backend specific configuration files for NetworkManager with netplan command:
sudo netplan generate
Start the NetworkManager Service:
sudo systemctl unmask NetworkManager
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager
Now the NetworkManager is enabled, interface configurations can be done via the GUI or from the command line, using the nmcli command.
While it is possible to manage networking on Ubuntu server via network manager, it has largely been replaced with Netplan. Therefore, it is recommended to use systemd-networkd on Ubuntu Server 18.04 and later.
https://www.configserverfirewall.com/ubuntu-linux/ubuntu-network-manager/
To write a message in a new text file and save it to the current directory, use Nano editor:
user@host-id:~$ nano testnote
That open an empty test file in the ./ current directory.
Type a message.
Press enter.
Press ctrl-x
Type y at the save buffer prompt.
At name to write prompt press enter.
user@host-id:~$
Run the list command to see the new filename.
ls
Press enter.
To read what is in a file, run the cat or more command.
Here the files are called testnote.
user@host-id:~$ cat testnote4
Here is the 4th note written with Nano.
or user@host-id:~$ more testnote5
Note 5 test in Nano.
user@host-id:~$
Cat is for concatenate and it works like combining information from more than one file into a catalogue.
To copy what is in one file and paste it into another file, adding one file to another, run a cat command with two >> arrows.
user@host-id:~$ cat testnote3 >> testnote4
user@host-id:~$ cat testnote4
Here is the 4th note written with Nano.
This is the third testnote written in Nano.
user@host-id:~$
The text of one file has been added to the text in the other.
Two arrows >> are needed to stop cat from overwriting a file with the same name, replacing the text.
To add the text of more than one file into another file:
cat filename1 filename2 >> filename3
user@host-id:~$ cat testnote1 testnote2 >> testnote4
cat: testnote1: No such file or directory
user@host-id:~$ cat testnote testnote2 >> testnote4
user@host-id:~$ cat testnote4
Here is the 4th note written with Nano.
This is the third testnote written in Nano.
Here is another test note written in Nano editor.
This is a test note with Nano text editor.bash: line 1: save: command not found
Here is another test note written in Nano editor.
user@host-id:~$
To redirect output from a cat command to a file:
jack@jack-U-H:~/Desktop$ cat >> ~/Desktop/output
This is text output from a cat command redirected to a file called output.
.
There you type your message into a blank space, press enter then full stop . then enter again, then ctrl-d to deliver the output.
user@host-id:~$ cat ~/Desktop/testfile
Test file not to be overwritten.
user@host-id:~$
That is what is already written in the testfile.
$ cat >> ~/Desktop/testfile
This note is added to the testfile from a cat command.
.
Ctrl-d
user@host-id:~$
To show what is added to the output file, run cat this way:
user@host-id:~$ cat ~/Desktop/testfile
Test file not to be overwritten.
This note is added to the testfile from a cat command.
.
user@host-id:~$
or when the filename is output
jack@jack-U-H:~/Desktop$ cat ~/Desktop/output
total 2244
drwxr-xr-x 3 jack jack 4096 Jun 27 10:02 .
drwxr-xr-x 26 jack jack 4096 Jun 27 07:12 ..
-rw-rw-r-- 1 jack jack 250 Jun 27 09:24 2DO
-rw-rw-r-- 1 jack jack 122 Jun 15 17:52 georgeuser
... etc
-rw-rw-r-- 1 jack jack 3836 Jun 26 20:47 xargstest
Add this output to the output file.
This is text output from a cat command redirected to a file called output.
Linux prints information output on to the computer screen.
To show or print on screen the names of the groups that a user is in, run the groups command:
e@ne-945GCM-S2L:~$ groups
username dialout cdrom plugdev lpadmin admin sambashare
That shows the user is an administrator and the only user of the computer and can use the cdrom drive and lp line printer.
To print the text in a file on to paper, use the lp line printer command.
lp filename
To print a file to the default printer:
lp filename
or lpr filename
To print to another printer than the default:
lp -d printername filename
or lpr -P printer filename
To print the output of a program:
program | lp
program | lp -d printername
or program | lpr
program| | lpr -P printername
The vertical line in those commands is called a pipe. Shell commands can be combined by piping one command into the next with the pipe | , which is shift \ backstroke on a keyboard.
To write and send a message to another user who is logged in on the same local server:
write username
Type a message.
Press enter
Press Ctrl-d to deliver the message.
The other user receives the message instantly and can answer right away.
user@host-id:~$ write user
write: user is not logged in
user@host-id:~$
To see who else is logged into the server:
w
es7@tom7-ID:~$ w
21:04:04 up 13:27, 1 user, load average: 0.01, 0.05, 0.13
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
tom7 tty2 tty2 07:50 13:27m 0.05s 0.05s /usr/libexec/gn
user@host-id:~$
TTY is Teletype.
https://phoenixnap.com/kb/write-command-in-linux
To write a note and set it aside for use later:
read
Run the read command without options.
Write or paste a note.
Press enter.
user@host-id:~$ read
A public key can be given to any person with whom an individual wants to communicate.
user@host-id:~$
To read that note later, run this echo command:
echo $REPLY
A public key can be given to any person with whom an individual wants to communicate.
user@host-id:~$
The echoed note can now be copied and pasted somewhere.
The note will be erased when the user logs out or shuts down the system.
To change the password of a user:
sudo passwd username
Follow prompts.
To check security permissions on sensitive files like passwd, shadow and sudo:
user@user-Inspiron-N5030:~$ ls -l /etc/passwd
These permissions are right for passwd. Only root can write w to this file.
-rw-r--r-- 1 root root 2297 tom 24 2019 /etc/passwd
user@user-Inspiron-N5030:~$ ls -l /etc/shadow
-rw-r----- 1 root shadow 1273 May 20 11:41 /etc/shadow
---------- 1 root root is the right setting for shadow. Even with no access permissions, root user can still access this shadow file. No other user can view the passwords in the shadow file.
The following commands and comments need reworking before being ready to add to the linuxsudeob10 file.
They are covered better by commands already in that file.
To view hash passwords as root:
user@user-Inspiron-N5030:~$ sudo tail -2 /etc/shadow
[sudo] password for user:
user:$6$i6CQZTDy$LtPYJxvUdl00Zn9xOrmRv6fASsfur./FliEOaSXnPkeUcOYmRUmtG0pCdW1NwDr19wjDj2sYuZS/LI6dpn5Ns/:18036:0:99999:7:::
guest-b4qdhb:!:17919::::::
An account for a guest user or any other user can be deleted.
user@user-ID:~$ ls -l /usr/bin/sudo
-rwsr-xr-x 1 root root 136808 tom 21 2017 /usr/bin/sudo
user@user-ID:~$
user@user-Inspiron-N5030:~$ sudo ls -l /usr/bin/sudo
[sudo] password for user:
-rwsr-xr-x 1 root root 136808 tom 21 2017 /usr/bin/sudo
Other permission settings for /usr/bin/sudo might be like those below.
user@user-Inspiron-N5030:~$
---s--x--x. 2 root root etc
Passwd and sudo commands should keep their settings.
To search the system for hidden or bad SUID or SGID commands:
user@user-Inspiron-N5030:~$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 54256 Mar 29 2016 /usr/bin/passwd
The permissions -rwsr-xr-x. 1 root root is alright for this passwd file. With these permissions, a user is still allowed temporarily to become root to change his password.
To check the permissions of the passwd and sudo files in the /usr/bin directory:
user@user-Inspiron-N5030:~$ sudo ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 54256 Mar 29 2016 /usr/bin/passwd
user@user-Inspiron-N5030:~$
Security programs include:
aide - to detect intrusions into the system;
chkrootkit - to detect rootkit malware; and
clamav - to detect viruses.
Port uses
Port Use
25 and 487 Email sending
20 FTP-data
21 FTP
22 SSH
23 Telnet
25 SMTP
42 nameserver
53 Domain
70 Gopher
79 Finger
80 HTTP
101 Hostname
107 Rtelnet
109 Pop2
110 Pop3
143 Imap
158 Pcmail-srv
194 IRC
443 HTTPS SSL
513/tcp Login
513/udp Who
517 talk
518 ntalk
520/udp router
529 irc-serv
532 netuse
546 dhcpv6-client
547 dhcpv6-server
565 whoami
989 ftps-data
990 ftps
992 telnets
993 imaps
994 ircs
995 pop3s
1167 phone
2703 sms-chat
3074 xbox
3587 p2pgroup
To remove old library files which are no longer being used:
Here the libs were left after Audacity was removed and purged.
b@tbox:~$ sudo apt-get purge audacity
[sudo] password for name:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'audacity' is not installed, so not removed
The following packages were automatically installed and are no longer required:
audacity-data libflac++6v5 libid3tag0 liblilv-0-0
libportsmf0v5 libsbsms10 libserd-0-0 libsord-0-0
libsratom-0-0 libsuil-0-0 libvamp-hostsdk3v5
Use 'sudo apt autoremove' to remove them.
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
b@tbox:~$ sudo apt-get autoremove
b@tbox:~$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done etc
Parallel Virtual Machine PVM is a software package which lets Linux, Unix and Windows operating systems link computers together to form a single large parallel computer. See pvm.txt.
To start python in Linux terminal and run a python command:
user@user-ID:~$ python
or type python3
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello, World!");
Hello, World!
Whatever is typed between the quotes will be printed to screen. The words between the quotes are called an arguement.
To exit python and go to a new command line in terminal, type ctrl-d .
To write a python script:
In terminal, run the editor command followed by the name of the script to be.
user@user-ID:~$ gedit hello.py
In gedit, write the lines of script.
#!/usr/bin/python
print ("hello world!")
Save the two-line script. There it is saved to the home directory. Move it to the ~/scripts/ directory where it can be found with other scripts.
To check the script, run cat:
user@user-ID:~$ cat scripts/hello.py
#!/usr/bin/python
print ("hello world!")
user@user-ID:~$
A python script starts with a hash # , or called a shebang. The #! line is the path to the directory holding the executable script.
The second line of the script is a command function, what the script is to do. Eg
#!/usr/bin/python
print ("hello world!")
To run the script:
$ python3 hello.py3
hello world!
user@user-ID:~$ python ~/scripts/hello.py
hello world!
user@user-ID:~$
The outpiut is hello world.
To learn python, follow the commands above then go to:
https://www.redhat.com/sysadmin/python-scripting-intro
and https://www.tutorialspoint.com/python/index.htm
Remmina remote access tool, rat, is already installed with Ubuntu.
user@user-ID:~$ remmina
Remmina plugin RDP (type=Protocol) registered.
Remmina plugin RDPF (type=File) registered.
Remmina plugin RDPS (type=Preference) registered.
Remmina plugin VNC (type=Protocol) registered.
Remmina plugin VNCI (type=Protocol) registered.
Remmina plugin SFTP (type=Protocol) registered.
Remmina plugin SSH (type=Protocol) registered.
^C
user@user-ID:~$
The remote computer must have the same RAT software installed and running.
To purge, remove, unistall, delete, install and upgrade Linux programs, see below.
To remove a program without removing its dependencies:
sudo apt-get remove programname
To uninstall remove a program and its depenencies if they are not used by other programs:
sudo apt-get autoremove programname
That will not remove any configuration files.
user@mail:~$ sudo apt-get autoremove dnsutils
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
dnsutils ubuntu-standard
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 365 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 173553 files and directories currently installed.)
Removing ubuntu-standard (1.361) ...
Removing dnsutils (1:9.10.3.dfsg.P4-8ubuntu1.4) ...
Processing triggers for man-db (2.7.5-1) ...
user@mail:~$
To remove the configuration and data files of a program:
sudo apt-get purge programname
user@mail:~$ sudo apt-get purge dnsutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'dnsutils' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
user@mail:~$
To remove a program with its dependent programs if they are not needed by other programs, and remove the configuration and data files of the program and its dependencies:
sudo apt-get autoremove --purge programname
To upgrade a particular program package:
apt-get upgrade programname
To install a program:
sudo apt-get install programname
To install a specific version of a program package, run:
apt-get install packagename=versionnumber
To upgrade all installed programs to their latest versions:
apt-get upgrade
To update refresh the system cache of packages and check for broken dependencies:
apt-get check
user@mail:~$ sudo apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
user@mail:~$
To show what packages may be deleted from the system when a program is removed:
dpkg -l | grep -i programname
user@mail:~$ dpkg -l | grep -i bind
ii bind9-doc 1:9.10.3.dfsg.P4-8 all Documentation for BIND
ii bind9-host 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 Version of 'host' bundled with BIND 9.X
ii bind9utils 1:9.10.3.dfsg.P4-8 amd64 Utilities for BIND
ii dnsutils 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 Clients provided with BIND
ii gir1.2-gtk-3.0:amd64 3.18.9-1ubuntu3.1 amd64 GTK+ graphical user interface library -- gir bindings
ii gir1.2-pango-1.0:amd64 1.38.1-1 amd64 Layout and rendering of internationalized text - gir bindings
ii gjs 1.44.0-1ubuntu1 amd64 Mozilla-based javascript bindings for the GNOME platform
ii libapparmor-perl 2.10.95-0ubuntu2.5 amd64 AppArmor library Perl bindings
ii libbind9-140:amd64 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 BIND9 Shared Library used by BIND
ii libdns162:amd64 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 DNS Shared Library used by BIND
ii libgjs0e 1.44.0-1ubuntu1 amd64 Mozilla-based javascript bindings for the GNOME platform
ii libindicator3-7 12.10.2+16.04.20151208-0ubuntu1 amd64 panel indicator applet - shared library
ii libisc160:amd64 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 ISC Shared Library used by BIND
ii libisccc140:amd64 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 Command Channel Library used by BIND
ii libisccfg140:amd64 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 Config File Handling Library used by BIND
ii liblwres141:amd64 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 Lightweight Resolver Library used by BIND
ii libnet-dbus-perl 1.1.0-3build1 amd64 Perl extension for the DBus bindings
ii libnet-libidn-perl 0.12.ds-2build2 amd64 Perl bindings for GNU Libidn
ii libnih-dbus1:amd64 1.0.3-4.3ubuntu1 amd64 NIH D-Bus Bindings Library
ii libunity-protocol-private0:amd64 7.1.4+16.04.20160701-0ubuntu1 amd64 binding to get places into the launcher - private library
ii libunity-scopes-json-def-desktop 7.1.4+16.04.20160701-0ubuntu1 all binding to get places into the launcher - desktop def file
ii libunity9:amd64 7.1.4+16.04.20160701-0ubuntu1 amd64 binding to get places into the launcher - shared library
ii libnameclient0:amd64 2:4.3.11+dfsg-0ubuntu0.16.04.3 amd64 Samba winbind client library
ii libxcb-dri2-0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, dri2 extension
ii libxcb-dri3-0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, dri3 extension
ii libxcb-glx0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, glx extension
ii libxcb-icccm4:amd64 0.4.1-1ubuntu1 amd64 utility libraries for X C Binding -- icccm
ii libxcb-image0:amd64 0.4.0-1build1 amd64 utility libraries for X C Binding -- image
ii libxcb-keysyms1:amd64 0.4.0-1 amd64 utility libraries for X C Binding -- keysyms
ii libxcb-present0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, present extension
ii libxcb-randr0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, randr extension
ii libxcb-render-util0:amd64 0.3.9-1 amd64 utility libraries for X C Binding -- render-util
ii libxcb-render0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, render extension
ii libxcb-shape0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, shape extension
ii libxcb-shm0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, shm extension
ii libxcb-sync1:amd64 1.11.1-1ubuntu1 amd64 X C Binding, sync extension
ii libxcb-util1:amd64 0.4.0-0ubuntu3 amd64 utility libraries for X C Binding -- atom, aux and event
ii libxcb-xfixes0:amd64 1.11.1-1ubuntu1 amd64 X C Binding, xfixes extension
ii libxcb-xkb1:amd64 1.11.1-1ubuntu1 amd64 X C Binding, XKEYBOARD extension
ii libxcb1:amd64 1.11.1-1ubuntu1 amd64 X C Binding
ii python-cairo 1.8.8-2 amd64 Python bindings for the Cairo vector graphics library
ii python-gobject-2 2.28.6-12ubuntu1 amd64 deprecated static Python bindings for the GObject library
ii python-gtk2 2.24.0-4ubuntu1 amd64 Python bindings for the GTK+ widget set
ii python-notify 0.1.1-4 amd64 Python bindings for libnotify
ii python-talloc 2.1.5-2 amd64 hierarchical pool based memory allocator - Python bindings
ii python3-brlapi 5.3.1-2ubuntu2.1 amd64 Braille display access via BRLTTY - Python3 bindings
ii python3-cairo 1.10.0+dfsg-5build1 amd64 Python 3 bindings for the Cairo vector graphics library
ii python3-commandnotfound 0.3ubuntu16.04.2 all Python 3 bindings for command-not-found.
ii python3-cups 1.9.73-0ubuntu2 amd64 Python3 bindings for CUPS
ii python3-gi 3.20.0-0ubuntu1 amd64 Python 3 bindings for gobject-introspection libraries
ii python3-gi-cairo 3.20.0-0ubuntu1 amd64 Python 3 Cairo bindings for the GObject library
ii python3-louis 2.6.4-2 all Python bindings for liblouis
ii python3-lxml 3.5.0-1build1 amd64 pythonic binding for the libxml2 and libxslt libraries
ii python3-pyatspi 2.18.0+dfsg-3 all Assistive Technology Service Provider Interface - Python3 bindings
ii python3-pycurl 7.43.0-1ubuntu1 amd64 Python bindings to libcurl (Python 3)
ii python3-systemd 231-2build1 amd64 Python 3 bindings for systemd
ii qml-module-io-thp-pyotherside:amd64 1.4.0-2 amd64 asynchronous Python 3 Bindings for Qt 5 (QML plugin)
user@mail:~$ dpkg -l | grep -i mutt
ii mutt 1.5.24-1build1 amd64 text-based mailreader supporting MIME, GPG, PGP and threading
user@mail:~$
There Bind is a program with many dependencies. A program it depends on a bit it DNSutilities which includes another program called Dig. So after Bind is removed, the system user may want to reinstall dnsutilities.
After a program has been installed, the system files need to be updated with this command:
apt-get update
That updates refreshes a list of programs installed or available for installation. It updates the package respository.
If a program fails to install properly, it may need to be purged and removed so that it can be reinstalled properly.
Some other apt-get commands like
apt-get dist-upgrade
apt-get dselect-upgrade
upgrade so many programs that they can harm the system and some programs installed.
To run apt-get with an option:
apt-get options command
apt-get options.
--no-install-recommends – only install main dependencies, do not include recommended packages
--install-suggests – install suggested packages as dependencies
-d/--download-only – download the packages without installing or unpacking them
-f/--fix-broken – attempt to correct a system with broken dependencies
-m/--ignore-missing/--fix-missing – ignore packages that cannot be retrieved
--ignore-hold – ignore packages placed on hold
--no-download – disable downloading packages
-q/--quiet – omit progress indicators and produce output suitable for logging
-s/--simulate/--just-print/--dry-run,--recon,--no-act - simulate events that would occur without actually change the system
-y/--yes/--assume-yes – assume "yes" as an answer to prompts
--assume-no - assume "no" as an answer to all prompts
--no-upgrade – do not upgrade packages (usually used with the install command to instruct apt-get not to upgrade if the package is already installed)
--only-upgrade – upgrade only installed packages
-V/--verbose-versions – display full versions of upgraded and installed packages
--show-progress – display progress bar while installing, removing or upgrading packages
>-b/--compile/--build – compile source packages once downloaded
--only-upgrade – upgrade only installed packages
--reinstall – reinstall installed packages to the netomt version
--auto-remove/--autoremove - remove unnecessary packages while installing a package
-h/--help – display a short usage summary
-v/--version – display the version of apt-get
-c/--config-file – specify which configuration file to read after the default one
-o/--option – set an arbitrary configuration option
To troubleshoot an installation failure:
Read any error message that pops up in Ubuntu. First disconnect from the internet so as not to send a bug report to Ubuntu developers.
For an example, a popup window says there has been a problem with the installation of a program called Postfix.Scroll down the message and click items to expand them. It says Myhost and domain names have been changed to Tecmint and these names have failed to be resolved.
In order for the developers to determine the cause of this, some potentially sensitive information from your system configuration may be helpful.
A further popup window says that the program called Postfix has an error in it. Further details say, Specifically, your hostname and DNS configuration. Please note that this will be included in a *PUBLIC* bug report.
Do you want to add this extra information to the bug report?
PostconfMyorigin: /etc/mailname
PostconfMydomain: tecmint.com
ResolvConf: # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.1.1
search tecmint.com
EtcMailname: user-ID
Hostname: Error: command ['hostname', '--fqdn'] failed with exit code 1: hostname: Temporary failure in name resolution
PostconfMyhostname: mail.tecmint.com
With the internet still disconnected, press the continue button and let the popup close without sending the bug report.
In this example, the error happened after Tecmint instructed to change the hostname in a Postfix config file. Look at the original config filed which is backed up to find the original hostname. Run the tecmint commands again but replace tecmint with the original hostname. So reset the valid FQDN Fully Qualified Domain Name hostname. If this fix fails, replace the whole config file with the original.
Here let's change the FQDN hostname to that of the ISP,
ozonline.com.au
202.173.192.224
mail.ozonline.com.au 25
mail.ozonline.com.au 143
Reconnect to the internet.
user@mail:~$ sudo hostnamectl set-hostname mail.ozonline.com.au
user@mail:~$
user@mail:~$ sudo service postfix restart
user@mail:~$
user@mail:~$ sudo /etc/init.d/sendmail restart
[ ok ] Restarting sendmail (via systemctl): sendmail.service.
user@mail:~$
user@mail:~$ hostname -f
popimap-proxy.ozonline.com.au
user@mail:~$
That's done. Now check the port is 143.
mydestination = $myhostname, user-ID, localhost.localdomain, , localhost
relayhost = mail.ozonline.com.au 143 202.173.192.224
Tecmint is changed to Ozonline.
user@mail:~$ sendmail malb@onionmail.org
sendmail: fatal: bad string length 0 < 1: myhostname =
user@mail:~$
Sendmail sees an error in the hostname.
Changed the hostname from empty to online again, deleting the port and ip numbers, and restarted postfix properly to keep the changes.
To make a new sendmail.cf file after changing the sendmail.mc file, run:
sudo sendmailconfig
Sent a test email to Onion but it was not received.
user@mail:~$ mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
AFC58606F5 332 Sat Apr 16 12:01:56 root@user-ID
(connect to mail.ozonline.com.au[203.23.159.157]:25: Connection refused)
malb@onionmail.org
-- 0 Kbytes in 1 Request.
user@mail:~$
That should be port 143, not 25, and the IP is different.
The original main.cf file says
myhostname = user-ID
with no port number.
user@mail:~$ mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
AFC58606F5 332 Sat Apr 16 12:01:56 root@user-ID
(connect to mail.ozonline.com.au[203.23.159.157]:25: Connection refused)
malb@onionmail.org
-- 0 Kbytes in 1 Request.
user@mail:~$
Mail is working because the mail and mailq commands do list emails received here and sent out but not delivered. Sendmail is working because mail sent to Onion is received. The last message to onion read,
Hi Mal,
This tes tis after changing host and relay host back to original values.
Chers,
user
So Postfix is working too after all the test configurations.
To list the dependencies of a package program:
apt-cache depends packagename
user@mail:~$ apt-cache depends bind9
bind9
Depends: libbind9-140
Depends: libc6
Depends: libcap2
Depends: libdns162
etc Suggests: ufw
Replaces: apparmor-profiles
Replaces:
Replaces: bind9utils
Replaces: dnsutils
user@mail:~$
To automatically download and install fix dependencies which are missing from an program alredy installed:
sudo apt-get -f install programname
user@mail:~$ sudo apt-get -f install bind9
[sudo] password for user:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
bind9 : Depends: libbind9-140 (= 1:9.10.3.dfsg.P4-8) but 1:9.10.3.dfsg.P4-8ubuntu1.4 is to be installed
Depends: libdns162 (= 1:9.10.3.dfsg.P4-8) but 1:9.10.3.dfsg.P4-8ubuntu1.4 is to be installed
Depends: libisc160 (= 1:9.10.3.dfsg.P4-8) but 1:9.10.3.dfsg.P4-8ubuntu1.4 is to be installed
Depends: libisccc140 (= 1:9.10.3.dfsg.P4-8) but 1:9.10.3.dfsg.P4-8ubuntu1.4 is to be installed
Depends: libisccfg140 (= 1:9.10.3.dfsg.P4-8) but 1:9.10.3.dfsg.P4-8ubuntu1.4 is to be installed
Depends: liblwres141 (= 1:9.10.3.dfsg.P4-8) but 1:9.10.3.dfsg.P4-8ubuntu1.4 is to be installed
E: Unable to correct problems, you have held broken packages.
user@mail:~$
Bind9 is no good. Remove it.
The root user or super user in Linux operating systems is like the administrator in Windows systems. The safest way to run commands as administrator in Terminal is not to log in as root but just to use sudo commands instead. Do not run programs while logged in as root. Run programs with the sudo command. Ubuntu locks the root user account by default.
To start the terminal program:
Press ctrl-alt-T
At the user prompt, type sudo passwd root
then press enter.
When prompted for a password, type your user password.
Set a new password
At this prompt type a new password, enter, and verify it.
The root account is now active.
The command prompt ends with hash # not dollar $.
To lock the root account again:
sudo passwd -dl root
To unlock the root account, edit the custom.conf file this way:
$ sudo nano /etc/gdm3/custom.conf
Type user password.
Scroll to the bottom of custom.conf.
Type
"AllowRoot=True" below "TimedLoginDelay = 10." Add a few spaces so that the "A" in "AllowRoot" goes right below the "T" in "TimedLoginDelay".
Press ctrl-x
See prompt to save the file.
Press y
then enter.
Back at the terminal prompt now type
sudo nano /etc/pam.d/gdm-password
Edit the password authentication file this way.
Type your password.
At the beginning of the third line, which says auth required pam_succeed_if.so user != root quiet_success, type a hash #.
The hash disables the third command line and that lets root log in using the root password.
Press ctrl-x
Type y to save the edited file.
To log in to an unlocked root account as super user:
ctrl-alt-T
type sudo without a password and press enter
Now type the root password.
An authentication error means that the root account is locked and
the command prompt ends with $. Unlock it.
At the prompt ending with #, or in some systems %, run sudo commands without being prompted for a password.
To reset a forgotten root password:
sudo passwd root
type or enter your user password
follow prompts to create a new root password
To set new root and user passwords, if both are forgotten or unknown:
Restart reboot the computer and hold down the shift key after the BIOS screen.
At the GRUB menu, select the first recovery mode entry on the list.
In recovery mode, select root option from the menu. This starts Terminal with you logged in as root.
Run this command to mount the hard drive and gain write permission.
# mount -rw -o remount /
Create new passwords for any accounts with this command.
# passwd accountname
to change the root password type
passwd root
when prompted, type a new password and press enter
type it again to verify it
Reboot the computer and use the new password to log in.
To gain root access:
user@user-localserver:~$ sudo su
[sudo] password for user:
root@user-localserver:/home/user#
The $ becomes # at the command prompt.
To log in on a Gnome system like Ubuntu, turn on the computer and at the Ubuntu login screen, click other or not listed?
In the login field, type root then press enter.
In the password field for root user, a password is already given. Just type enter.
To log in as root using Terminal:
$
$ sudo
$ root@ubuntu:/homeusername#
That is the command prompt for the root user.
To log in as root on a remote computer, use SSH, secure shell.
ssh [email protected]
Cloudbad is protecting this email address from robots. So enable javascript to see the email address.
To show the gateway address for the IPv6 interface of the network:
route -n6
user@localhost-ID:~$ route -n6
Kernel IPv6 routing table
Destination Next Hop Flag Met Ref Use If
fe80::/64 :: U 256 0 0 eth0
::/0 :: U 1024 0 0 eth0
::/0 :: !n -1 1 19 lo
::1/128 :: Un 0 1 5 lo
fe80::221:9bff:fe0d:e9c6/128 :: Un 0 1 27 lo
ff00::/8 :: U 256 0 0 eth0
::/0 :: !n -1 1 19 lo
user@localhost-ID:~$
The IPv6 gateway starts with fe80 and ends with a higher /number. Here it is
fe80::221:9bff:fe0d:e9c6/128
for the lo local area network LAN.
That is the IPv6 routing table.
To show the gateway Ip address, genmask, ip address on the IP routing table:
route
user@localhost-ID:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
user@localhost-ID:~$
The metri speed is 1000.
or run route n
netstat -rn
ip route list
user@localhost-ID:~$ ip route list
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 1
169.254.0.0/16 dev eth0 scope link metric 1000
default via 192.168.1.1 dev eth0 proto static
user@localhost-ID:~$
Spreadsheet Calculator SC runs from the Linux command line.
https://www.linuxjournal.com/article/10699
To run Spreadsheet Calculator:
sc
In Terminal, username@:~$ sc
A blank spreadsheet opens in Terminal.
Press shift-? for help.
Never run SC as root user.
To close or exit SC, press q for quit.
Do you want to save the data?
Press n for no or y for yes.
Or press enter then q.
To install Spreadsheet Calculator:
username@:~$ sc
Command 'sc' not found, but can be installed with:
sudo apt install sc
username@:~$ sudo apt install sc
[sudo] password for tom7:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically install etc
To learn how to use SC:
Start sc, see an empty spread sheet with a command line at the top,
type a question mark, shift-?,
press the a key then b and c through to p to learn and practise the commands.
To move the cursor to another cell or co-ordinate, press the arrow keys.
To go to a cell, type its co-ordinates:
g cordinates
eg g b7
A cor-ordinate, or cell address, is a combination of a letter from the top row and a number from the left column to pinpoint a cell. Column names are not case sensitive.
To go to a word or regular expression:
g "typed words" in quotes
eg g " Tax table ".
To go to a number:
g number
eg g 238
To insert a row or column into the spreadsheet, press i then r or c.
To type a number into a cell:
Press the arrow keys to highlight the cell.
Press the e key.
Type the number then press enter.
To enter a numeric constant or expression into the currently highlighted cell:
Press the equal key = then type the number at the prompt on the top line.
To type enter a label string into the current cell:
Type < followed by a word or words.
To left justify a word in the current cell, press the curly bracket key, { , shift-bracket.
To erase delete a number from a cell:
Press arrow keys to highlight the cell.
Press x key then enter key.
To go back to the i> prompt, press enter.
See cursor flashing.
To open SC with a tutorial about the spreadsheet calculator, run this command in Terminal:
sc /usr/share/doc/sc/tutorial.sc
Drag the screen wider to read lines.
or try sudo gunzip /usr/share/doc/sc/tutorial.sc.gz
To scroll the tutorial document, click it with the mouse then press the down arrow key.
To scroll a document page by page, press the pageup amnd pagedown keys.
Cells can contain numbers, formulas or text.
To show what is in a cell, highlight the cell. Its contents is shown between backets at the top left of the screen.
To type data into a cell:
Highlight the cell then type
mkdir test ; \
> cd test/
Desktop Downloads Music Programs Templates Tubes
Documents examples.desktop Pictures Public Transfers Videos
user:~/test$
There are three commands joined by two backslashes.
To remove several directories at once:
user:/media/160gbSamsung/home/user/.locker2$ ls
cover gpgarchive.tar karate karate1.zip newdir2 testlockssl
cover.zip ics9779 karate1 karate.zip testgpg testlock.zip
user:/media/160gbSamsung/home/user/.locker2$ rm cover/* karate/* newdir2/* ics9779/* karate1/*; rmdir cover karate newdir2 ics9779 karate1
user:/media/160gbSamsung/home/user/.locker2$ ls
cover.zip karate1.zip testgpg testlock.zip gpgarchive.tar karate.zip testlockssl
user:/media/160gbSamsung/home/user/.locker2$
Asterists * are used there to remove files out of the directories before removing the directories. Files and directories are listed with one space between them and no punctuation.
To remove groups of files:
Here a remove command has two wildcars * telling it to remove all files with names beginning with k or t.
user:/media/160gbSamsung/home/user/.locker2$ ls
gpgarchive.zip karatee.zip testlockssl testssl
karate1.zip karate.zip testlockssld testssld
karateed testgpg testlock.zip testssle
user:/media/160gbSamsung/home/user/.locker2$ rm k* t*
user:/media/160gbSamsung/home/user/.locker2$ ls
gpgarchive.zip
user:/media/160gbSamsung/home/user/.locker2$
Three operator characters used to combine commands are:
the semicolon ;
the double and &&
and the double pipe ||
All should have a space either side of them as that helps to separate the commands and make them easier to read.
As mentioned above, the semicolon says to run the next command even if the earlier command failed.
The && says to run the next command only if the earlier command succeeds.
The || says run the next command only if the earlier command failed.
It is safer to join commands with && and use the double and to join most commands. Data can be lost by forcing a command to run even though an earlier command fails. Think about what the commands will do before you choose to type a semicolon or double pipe between them.
A single pipe | gives the output of one command to the next command as input to work on.
A single & works like a ; but runs the earlier command in the background.
To copy library files from one directory to another. Sudo needs a password for the system administrator to copy these program dependency files. R is recursive and i is interactive. Two slashes say the first directory or folder /leb is in the root system directory. A ~ shows that the destination folder /libs is in the /home/user directory.
username@hostname-ID:~/Desktop/libs$ sudo cp -Ri //lib ~/Desktop/libs
username@hostname-ID:~/Desktop/libs$
If a copy cp command does not work, look at it to find out what is wrong with it, fix it and try again. Copy and paste commands to save typing and reduce errors.
This error message says that the cp command above did not work.
bash: username@hostname-ID:~/Desktop/libs$: No such file or directory
To list the files in the source and destination directories to check what has been copied.
username@hostname-ID:~/Desktop/libs$ ls
Nothing in the destination directory.
username@hostname-ID:~/Desktop/libs$ cd /lib
username@hostname-ID:/lib$ ls
brltty libnss_files-2.12.1.so
cpp libnss_files.so.2
dbus-1.0 libnss_hesiod-2.12.1.so
fglrx etc
libcidn-2.12.1.so libply-splash-etc core.so.2.0.0
libcidn.so.1 libply-splash-graphics.so.2
libcom_err.so.2 libply-splash-graphics.so.2.0.0 etc
libnss_compat-2.12.1.so udev
libnss_compat.so.2 ufw
libnss_dns-2.12.1.so xtables
libnss_dns.so.2
username@hostname-ID:/lib$
None of the lib files were copied.
Here change to the the root directory and run the same sudo command. That worked. If an overwrite propt shows, type y and Enter to overwrite the file that is already in the destination directory. But as there are many files to copy and no files to overwrite, the -i command may be deleted.
username@hostname-ID:~$ cd /
username@hostname-ID:/$
username@hostname-ID:/$ sudo cp -Ri //lib ~/Desktop/libs
[sudo] password for user:
A better command may be to add the no command -n . This will override the -i command and tell Terminal not to overwrite any file that is already in the destination directory.
eg cp -n myoldfile.txt mycopiedfile.txt
username@hostname-ID:/$ sudo cp -Rin //lib ~/Desktop/libs
username@hostname-ID:~$ cd /
username@hostname-ID:/$ username@hostname-ID:/$ sudo cp -Rin //lib ~/Desktop/libs
username@hostname-ID:~$ cd /
username@hostname-ID:/$ username@hostname-ID:/$ sudo cp -Rin //lib ~/Desktop/libs
bash: username@hostname-ID:/$: No such file or directory
username@hostname-ID:/$ sudo cp -Rin //lib ~/Desktop/libs
[sudo] password for user:
username@hostname-ID:/$ sudo cp -R //lib ~/Desktop/libs
username@hostname-ID:/$
The last command above does not have an -i or an -n.
The next commands show that lib files are copied to the new /libs/lib directory.
username@hostname-ID:/$ sudo cp -Rin //lib ~/Desktop/libs
[sudo] password for user:
username@hostname-ID:/$ sudo cp -R //lib ~/Desktop/libs
username@hostname-ID:/$ cd ~/Desktop/libs$
bash: cd: /home/user/Desktop/libs$: No such file or directory
username@hostname-ID:/$ cd /home/user/Desktop/libs
username@hostname-ID:~/Desktop/libs$ ls
brltty firmware lib modules security ufw
dbus-1.0 hdparm linux-sound-base oss-compat terminfo
fglrx init lsb plymouth udev
libbsd.so.0.2.0 libpcsclite.so.1
libbz2.so.1 libpcsclite.so.1.0.0
libbz2.so.1.0 libply-boot-client.so.2
libbz2.so.1.0.4 libply-boot-client.so.2.0.0
libc-2.12.1.so libply.so.2
etc libnss_compat.so.2 ufw
libnss_dns-2.12.1.so xtables
libnss_dns.so.2
username@hostname-ID:~/Desktop/libs/lib$
To run 32-bit programs on 64-bit installations of Ubuntu, install the package ia32-libs:
markus@ubuntu:~$ sudo apt-get install ia32-libs
You might get away with installing the 32bit libraries.
satom@volus:~$ sudo apt-cache search ia32-libs
ia32-libs - ia32 shared libraries - transitional package
ia32-libs-multiarch - Multi-arch versions of former ia32-libraries
satom@volus:~$ sudo apt-get install ia32-libs
To resolve /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory issue
On Debian or Ubuntu:
sudo apt-get install ia32-libs
To show permissions of files and directrories:
user@host-id:~$ ls -l
total 100
-rw-rw-r-- 1 tom7 tom7 0 Nov 26 11:30 2023112609000000
-rw-rw-r-- 1 tom7 tom7 0 Nov 26 11:28 20231126112700
-rw-rw-r-- 1 tom7 tom7 5619 Jun 25 14:01 certifs.pem
drwxr-xr-x 3 tom7 tom7 4096 Dec 2 16:25 Desktop
drwxr-xr-x 2 tom7 tom7 4096 Oct 12 09:09 Documents
drwxr-xr-x 2 tom7 tom7 4096 Nov 27 15:33 Downloads
d etc
To show permissions of programs:
user@host-id:~$ ls -al /etc/
total 1244
drwxr-xr-x 136 root root 12288 Dec 2 17:07 .
drwxr-xr-x 20 root root 4096 May 27 2023 ..
etc rwxr-xr-x 3 root root 4096 Feb 23 2023 alsa
drwxr-xr-x 2 root root 4096 Nov 17 13:17 alternatives
-rw-r--r-- 1 root root 335 Mar 23 2022 anacrontab
-rw-r--r-- 1 root root 433 Mar 23 2022 apg.conf
etc drwxr-xr-x 8 root root 4096 Jun 8 08:51 apt
drwxr-xr-x 3 root root 4096 Nov 21 06:36 avahi
-rw-r--r-- 1 root root 2319 tom 7 2022 bash.bashrc etc
drwxr-xr-x 2 root root 4096 Feb 23 2023 bluetooth
-rw-r- etc
To show which default program is interpreting the shell commands:
user:~$ who am i
user pts/0 2019-07-24 13:34 (:0.0)
user:~$ grep user /etc/passwd
user:x:1000:1000:user,,,:/home/user:/bin/bash
user:~$
The default interpreter is Bash, which is the usual default for Linux distributions Fedora and Ubuntu.
If a correctly copied command or script does not work, try it again using a different shell interpreter. To choose a command interpreter program, type the name of the interpreter as a command. The names of some other interpreters are: sh, dash, ksh and tcsh. Type the exit command to leave an interpreter.
user:~$ sh
$ exit
user:~$ dash
$ exit
user:~$ ksh
The program 'ksh' can be found in the following packages:
* pdksh
* zsh
* ksh (You will have to enable component called 'universe')
* mksh (You will have to enable component called 'universe')
Try: sudo apt-get install
user:~$ tcsh
The program 'tcsh' is currently not installed. You can install it by typing:
sudo apt-get install tcsh
You will have to enable the component called 'universe'
user:~$
That shows Bash, Dash and Sh are three command interpreters which are installed along with Ubuntu.
To learn how to us a command interpreter, type:
man interpretername
and press return or enter key.
user:~$ man sh
Read the manual on screen.
To close a manual, press the q key to quit.
To automatically reuse a command used before Terminal was last exited and closed down:
Try the history command.
$ history n
user:~$ man sh
user:~$ history 5
893 dash
894 ksh
895 tcsh
896 man sh
897 history 5
user:~$
Here n is the number of most recent commands to be shown.
Copy and past the command to be reused at a new $ command prompt and edit it.
Running an old command automatically without checking it, by typing an exclamation mark ! number, the number listed with the command, may be a risky practice as some commands listed in history may be mistakes. A better practice may be to copy and past correct commands into a text file which can be searched later.
To find and check an earlier command before running it, press the up and down arrow keys to scroll a list of commands used earlier, edit the command if need be then press enter to run it.
To find the process identifier number PID of a program:
$ ps -e | grep programname
Here ps looks through a list of -e every program running on the computer then grep finds on that list the ID number of the program named.
user:~$ ps -e | grep gedit
1906 ? 00:00:26 gedit
user:~$
The number of the program Gedit is 1906.
To kill or shut down a program:
$ kill pidnumber
eg user:~$ kill 1906
user:~$
Gedit closes and shuts down.
To show what usb devices are on the computer:
usern:~$ lsusb
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 003: ID 1c4f:0003 SiGma Micro HID controller
Bus 005 Device 002: ID 1a2c:0002
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
usern:~$
To show more information about the usb devices, add the -v verbose option:
usern:~$ lsusb
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 003: ID 1c4f:0003 SiGma Micro HID controller
Bus 005 Device 002: ID 1a2c:0002
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
usern:~$
That shows that the sigma device is the mouse. A faulty usb stick plugged in did not show up at all in the list.
To find out about as usb device:
Plug the device in and wait for it to automatically load.
In Terminal, run the sudo list usb command:
usern:~$ sudo lsusb
Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 003: ID 1c4f:0003 SiGma Micro HID controller
Bus 005 Device 002: ID 1a2c:0002
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 004: ID 148f:7601 Ralink Technology, Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
usern:~$
The device is by Ralink Technology.
For more info about Ralink:
Bus 002 Device 004: ID 148f:7601 Ralink Technology, Corp.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.01
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x148f Ralink Technology, Corp.
idProduct 0x7601
bcdDevice 0.00
iManufacturer 1 MediaTek
iProduct 2 802.11 n WLAN
iSerial 3 1.0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 74
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
(Bus Powered)
MaxPower 160mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 8
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x84 EP 4 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x85 EP 5 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x08 EP 8 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x04 EP 4 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x05 EP 5 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x06 EP 6 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x07 EP 7 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x09 EP 9 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0000
(Bus Powered)
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 9 Hub
bDeviceSubClass 0 Unused
bDeviceProtocol 0 Full speed (or root) hub
bMaxPacketSize0 64
idVendor 0x1d6b Linux Foundation
idProduct 0x0002 2.0 root hub
bcdDevice 2.06
iManufacturer 3 Linux 2.6.35-22-generic ehci_hcd
iProduct 2 EHCI Host Controller
iSerial 1 0000:00:1d.7
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 25
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xe0
Self Powered
Remote Wakeup
MaxPower 0mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 9 Hub
bInterfaceSubClass 0 Unused
bInterfaceProtocol 0 Full speed (or root) hub
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0004 1x 4 bytes
bInterval 12
Hub Descriptor:
bLength 9
bDescriptorType 41
nNbrPorts 6
wHubCharacteristic 0x000a
No power switching (usb 1.0)
Per-port overcurrent protection
bPwrOn2PwrGood 10 * 2 milli seconds
bHubContrCurrent 0 milli Ampere
DeviceRemovable 0x00
PortPwrCtrlMask 0xff
Hub Port Status:
Port 1: 0000.0100 power
Port 2: 0000.0100 power
Port 3: 0000.0503 highspeed power enable connect
Port 4: 0000.0100 power
Port 5: 0000.0100 power
Port 6: 0000.0100 power
Device Status: 0x0003
Self Powered
Remote Wakeup Enabled
Ralink Technology, Corp.
It shows that the device is a wakeonlan usb plugin made by RealTek but does not say that it is a wifi adapter.
Swapfile
A swap file will work in with any existing swap space on the hard drive of the computer, such as a swap file or a swap partition.
To check what swap space is available:
free -h
user:~$ free -h
total used free shared buff/cache available
Mem: 3.8Gi 903Mi 1.6Gi 52Mi 1.3Gi 2.7Gi
Swap: 3.8Gi 0B 3.8Gi
user:~$
Widen the screen to show the table.
Or run swapon -show
user:~$ swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 3.8G 0B -2
user:~$
No output would mean no swap file.
To show where the swapfile is in the root directory:
ls /
user:~$ ls /
bin dev lib libx32 mnt root snap sys var
boot etc lib32 lost+found opt run srv tmp
cdrom home lib64 media proc sbin swapfile usr
user:~
To make a swap file:
sudo mkswap /swapfile
To change permissions so only root can edit the swapfile, run chmod:
sudo chmod 600 /swapfile
To to turn on and activate a new swapfile:
sudo swapon /swapfile
where /swapfile is the name of the swap file.
To reactivate the swapfile every time the computer reboots:
sudo gedit /etc/fstab
Add this line to the bottom of that file.
/swapfile none swap sw 0 0
Save the changes and close the editor.
To show if the swapfile is being used:
swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 3.8G 0B -2
user:~
A negative number means priorities are automatically allocated.
To make create a new swap file:
sudo dd if=/dev/zero of=/swapfile2 bs=1024 count=104857
sudo mkswap /swapfile2
sudo chmod 600 /swapfile2
sudo swapon /swapfile2
Edit the /etc/fstab file as shown above.
swapon --show
To deactivate or turn off a swapfile:
Edit the /etc/fstab file by typing a hash # at the beginning of the swapfile line to commenting it out. Or erase that whole line.
Save the changes.
Restart the computer.
To remove a swapfile or replace one swap file with another:
First deactivate the swapfile as above then restart the computer.
sudo rm /swapfile
Or whatever the swapfile is named.
See change permissions above.
To run TC linux networking commands:
see also lansetup.txt
To check that tc is installed:
tc
To install tc:
sudo apt-get install iproute-tc
or sudo apt-get install iproute2
To view show the qdiscs queues applied on every network interface on our system:
sudo tc qdisc show
See output like this -
qdisc noqueue 0: dev lo root refcnt 2
qdisc noqueue 0: dev eth0 root refcnt 2
qdisc noqueue 0: dev eth1 root refcnt 2
A noqueue disk does not delay data packages in any queue but sends them out as soon as it receives them.
To run a command as administrator, user root, use:
sudo command
To run the manual for user root:
man sudo_root
See terminald.txt
Time stamps, touch and list usage
https://phoenixnap.com/kb/touch-command-in-linux
Touch modifies changes the timestamp of a file. There are three timestamps in Linux: modification timestamps, access time and change time.
The change timestamp tells when the properties of the file were last changed. The modification stamp shows when the contents of the file was last changed. The access time shows when a user last opened the file.
To show the access timestamp of a file:
To change the timestamp of a file to the current time:
touch filename
name@name-ID:~$ touch ./Desktop/testfile
name@name-ID:~$
If no file named testfile is in the directory, touch will make a new file by that name.
To show the time stamp of a file:
ls --full-time filename
There the file is in the current directory ./
name@name-ID:~/Desktop$ ls --full-time test
-rw-rw-r-- 1 tom7 tom7 8565 2023-11-21 15:41:57.404108464 +1100 test
name@name-ID:~/Desktop$
There the file called test in the current directory called Desktop has a time stamp of 19 minutes to 4 o'clock on the 21st of November.
That same list command also shows that user tom created the file and has permission to rw read and write files. Because the test file already exists, List does not change the time stamp.
To show the owner of a file:
ls -l filename
name@name-ID:~/Desktop$ ls -l test
-rw-rw-r-- 1 tom7 tom7 8565 Nov 21 15:41 test
name@name-ID:~/Desktop$
tom owns the test file and created it on Nov 21.
The -l option or flag formats the output information in one line.
Touch shows the access and modification time stamps of a file.
To change the time a file was last accessed to the current time, run the touch command with an -a option:
touch -a filename
name@name-ID:~/Desktop$ touch -a test
name@name-ID:~/Desktop$
To show the changed timestamp,
name@name-ID:~/Desktop$ ls -lu test
-rw-rw-r-- 1 tom7 tom7 8565 Nov 25 21:20 test
name@name-ID:~/Desktop$ ls -l test
-rw-rw-r-- 1 tom7 tom7 8565 Nov 21 15:41 test
name@name-ID:~/Desktop$
To change the time a file was last modified -m :
touch -m filename
name@name-ID:~/Desktop$ touch -m test
name@name-ID:~/Desktop$ ls -l test
-rw-rw-r-- 1 tom7 tom7 8565 Nov 25 21:37 test
name@name-ID:~/Desktop$
The stamp has changed to the current time.
To set a timestamp for an existing file:
touch timestamp filename
A timestamp is written like this
CCYY MMDDhhmmss
That is for century, year, month, day, hour, minutes and seconds.
eg touch 20230209000000 filename
name@name-ID:~$ touch 20231126112700 testfile
name@name-ID:~$
There the stamp was changed to the current date.
This next command changes the stamp to another time.
name@name-ID:~$ touch 2023112609000000 testfile
name@name-ID:~$
That testfile is in the home directory whereas the first testfile is in the Desktop directory.
To show the timestamp of a file:
ls --full-time filename
name@name-ID:~$ ls --full-time testfile
-rw-rw-r-- 1 tom7 tom7 0 2023-11-26 11:30:55.213802179 +1100 testfile
name@name-ID:~$
Note that the stamp still has the current time.
To change only the access time, use the -a option.
touch -a filename
To change only the modification time, use the -m option.
touch -m filename
To make a new empty text file in the current directory:
touch filename
name@name-ID:~/Desktop$ touch testfile
name@name-ID:~/Desktop$ ls
linksbrowser
'abazure2023-09-21 19-08-21.png' luakitinstall
etc gsbterm2023-10-19 13-48-19.png' test
hexchatlog testfile
httpsites timesudo
independentsoftware trisquel
installc etc
name@name-ID:~/Desktop$
The new testfile is there.
Touch will not make a file if a file by the same name is already in the directory. But it will change the timestamp of the existing file. So generally do not use touch to make new files.
To write a message in a new text file and save it to the current directory, use Nano editor:
name@name-ID:~$ nano testnote
That open an empty test file in the ./ current directory.
Type a message.
Press enter.
Press ctrl-x
Type y at the save buffer prompt.
At name to write prompt press enter.
name@name-ID:~$
Run the list command to see the new filename.
ls
Press enter.
To toggle between the last two directories opened:
cd -
That's hyphen.
To toggle between two open terminal windows:
Alt-Tab
or Alt-~
That's tilde.
Linux ip tunnel command is mainly for network tunnelling, tunnel keys and TTL/TOS manipulation.
To check if iptunnel is installed:
ip tunnel show
jill@mail:~$ ip tunnel show
A blank line shows it is installed.
To show the usage of iptunnel:
iptunnel -?
jill@mail:~$ iptunnel -?
Usage: iptunnel { add | change | del | show } [ NAME ]
[ mode { ipip | gre | sit } ] [ remote ADDR ] [ local ADDR ]
[ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]
[ ttl TTL ] [ tos TOS ] [ nopmtudisc ] [ dev PHYS_DEV ]
iptunnel -V | --version etc
Iodine server
see iodinesudo.txt
Server and client need to be running the same version of iodine.
To uninstall programs using Linux Terminal:
First read all the tutorial file called uninstalsudo.txt before running any of the uninstall commands.
To manage user accounts, priveleges, permissions and preferences:
To show who is the current user:
user@host-id:~$ whoami
tom7
user@host-id:~$
To change your password:
user@host-id:~$ passwd tom7
Changing password for tom7.
Current password:
New password:
Keep note of the new password.
To show user account information in the /etc/passwd file:
user@host-id:~$ ls -al /etc/passwd
-rw-r--r-- 1 root root 3108 Nov 29 19:56 /etc/passwd
user@host-id:~$
To add a new user of the system:
sudo useradd -c comment accountname
Replace comment with the name of the user.
user@host-id:~$ sudo useradd -c testuser testguy
[sudo] password for tom7:
user@host-id:~$
That new user is named testuser and his accountname is testguy.
To give a password to a new user:
user@host-id:~$ sudo passwd testguy
New password:
Retype new password:
passwd: password updated successfully
user@host-id:~$
psd kS2_
To check the status -S of a user:
sudo passwd -S accountname
user@host-id:~$ sudo passwd -S testguy
testguy P 12/03/2023 0 99999 7 -1
user@host-id:~$
P means password is set.
LK password locked means user needs a new password.
or mick@host-id:~$ sudo passwd -S mick
[sudo] password for mick:
mick P 10/04/2023 0 99999 7 -1
mick@host-id:~$
To remove or expire -e a password:
sudo passwd -e accountname
eg sudo passwd -e testguy
user@host-id:~$ sudo passwd -e testguy
passwd: password expiry information changed.
user@host-id:~$
user@host-id:~$ sudo passwd -S testguy
testguy P 01/01/1970 0 99999 7 -1
user@host-id:~$
1970 means the password has expired.
To unlock a user account, set a password for it.
sudo passwd accountname
user@host-id:~$ sudo passwd testguy
New password:
Retype new password:
passwd: password updated successfully
user@host-id:~$
To lock -l an account:
sudo passwd -l accountname
user@host-id:~$ sudo passwd -l testguy
passwd: password expiry information changed.
user@host-id:~$
To unlock -u an account:
user@host-id:~$ sudo passwd -u testguy
passwd: password expiry information changed.
user@host-id:~$
user@host-id:~$ sudo passwd -S testguy
testguy P 12/03/2023 0 99999 7 -1
user@host-id:~$
To set an expiry time -x for a password and a warning -w for when it is about to expire:
sudo passwd -x 365 -w 7 accountname
That password expires in 90 days.
To delete and remove -r an account:
disable it, backup the home directory then remove the account.
userdel
sudo userdel -r accountname
https://www.redhat.com/sysadmin/linux-user-account-management
Flags are options. The enter key is the return key.
To hack a command from a web or test page:
Drag the cursor over the command to highlight it.
Paste it on to the command line in Terminal.
Edit it as need be.
Delete any space before and after the command.
Execute the command by pressing enter.
To show the shadow file for encrypted passwords at /etc/shadow :
user@host-id:~$ sudo cat ls /etc/shadow
[sudo] password for tom7:
root:!:19501:0:99999:7:::
daemon:*:19411:0:99999:7:::
bin:*:19411:0:99999:7:::
sys:*:19411:0:99999:7:::
sync:*:19411:0:99999:7:::
games:*:19411:0:99999:7:::
man:*:19411:0:99999:7:::
lp:*:19411:0:99999:7:::
mail:*:19411:0:99999:7:::
news:*:19411:0:99999:7::: etc
tom7:$y$j9T$rCnameqQsCAMxbv29K0JoQk/$Rs3oM2ilWuegUnBkjwNOCgyHrV4ukrpuOg49CuADGx2:19501:0:99999:7:::
snapd-range-524288-root:!:19593::::::
snap_daemon:!:19593::::::
ftp:*:19688:0:99999:7:::
keith:$y$j9T$ByO6IREELpZoDA6J1zA0i0$2IugGZrz7rmzGba0FKO3fl46GTyAgKBK3kFfO337HZD:19690:0:99999:7:::
testguy:$y$j9T$83URJR1MwUD7l6nUu2Duc1$zGsAlVKDm0ANPptIZQwsBNtM6Kqe6qe3Zj.ZH7s9xf1:19694:0:99999:7:::
user@host-id:~$
To give root privileges to a user by adding him to the root's group -G:
sudo usermod -G root username
Root is the name of the group.
user@host-id:~$ sudo usermod -G root keith
[sudo] password for tom7:
user@host-id:~$
or useradd -m -G root username
user@host-id:~$ sudo useradd -m -G root keith
useradd: user 'keith' already exists
user@host-id:~$
That user is already in the administrator's group.
To remove a user from the root group but leave his account on the system:
To show a list of all users in the /etc/passwd file:
cat /etc/passwd
user@host-id:~$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin etc
gdm:x:128:134:Gnome Display Manager:/var/lib/gdm3:/bin/false
tom7:x:1000:1000:tom,,,:/home/tom7:/bin/bash
snapd-range-524288-root:x:524288:524288::/nonexistent:/usr/bin/false
snap_daemon:x:584788:584788::/nonexistent:/usr/bin/false
ftp:x:129:137:ftp daemon,,,:/srv/ftp:/usr/sbin/nologin
keith:x:1002:1002:,,,:/home/keith:/bin/bash
testguy:x:1003:1003:testuser:/home/testguy:/bin/sh
user@host-id:~$
Users are tom7, keith and testguy.
To show a short list of all the users on the system:
getent passwd {1000..60000}
user@host-id:~$ getent passwd {1000..60000}
tom7:x:1000:1000:tom,,,:/home/tom7:/bin/bash
keith:x:1002:1002:,,,:/home/keith:/bin/bash
testguy:x:1003:1003:testuser:/home/testguy:/bin/sh
user@host-id:~$
The default username ID for root is 0 . Each user has an identity number, a UID.
To shorten the arguement list of users for getent:
mick@host-id:~$ sudo getent passwd {1000..60000}
sudo: unable to execute /usr/bin/getent: Argument list too long
mick@host-id:~$ sudo getent passwd {1000..20000}
mick:x:1000:1000:mick,,,:/home/mick:/bin/bash
mick@host-id:~$
Edit the numbers in brackets as above.
To send an email to a remote webmail address:
mick@host-id:~$ mail walb@onionmail.org
Cc: root
Subject: Onion test
Hi Walbee,
mick sends this to you using mail command.
Cheers,
mick
.
Ctrl-d to deliver or send the email.
mick@host-id:~$
To show the mail inbox:
mick@host-id:~$ mail
Cannot open mailbox /var/mail/mick: Permission denied
No mail for mick
mick@host-id:~$
A service is configured for Root to receive all mail. So run a sudo mail command.
sudo mail
[sudo] password for mick:
"/var/mail/root": 1 message 1 new
>N 1 mick Thu Dec 7 14:54 18/528 Onion test
? 1
Type 1 to read message 1.
Return-Path:
X-Original-To: root@mick-945GZM-S2
Delivered-To: root@mick-945GZM-S2
Received: by mick-945GZM-S2 (Postfix, from userid 1000)
id 15A4BA9A7F; Thu, 7 Dec 2023 14:54:08 +1100 (AEDT)
To:
Cc:
Subject: Onion test
X-Mailer: mail (GNU Mailutils 2.99.99)
Message-Id: <20231207035408.15A4BA9A7F@mick-945GZM-S2>
Date: Thu, 7 Dec 2023 14:54:08 +1100 (AEDT)
From: mick@host-id (mick)
Hi Wabee,
mick sends this to you using mail command.
Cheers,
mick
.
Root administrator received a copy of the email CC from mick.
mick does not have root privileges to open an email.
?
? q
Saved 1 message in /home/mick/mbox
Held 0 messages in /var/mail/root
mick@host-id:~$
Walbee did not receive the email at Onionmail.
This Mail is configured for local emails only.
To run the visudo editor:
sudo visudo
Choose from menu.
Saving a sudo file with errors in it can lock the administrator out of the operating system.
Vim editor is not like visudo.
To run the vim editor:
vi
Type a slash / to show a command line.
Do not use that editor.
VLC - A command-line version of VLC media player can be installed from debian packages in the repository for Ubuntu 10.
Then run the vlc command for a dummy interface, that is without a gui, graphic user internface.
Terminal commands for VLC:
jill@host:~$ vlc --help
VLC media player 1.1.4 The Luggage (revision exported)
Usage: vlc [options] [stream] ... etc
Use the scroll bar in Terminal.
Or run vlc -H for longer help
To print a list of available modules:
vlc -l
jill@host:~$ vlc -l
VLC media player 1.1.4 The Luggage (revision exported)
packetizer_h264 H.264 video packetizer
packetizer_copy Copy packetizer
packetizer_flac Flac audio packetizer etc
To run the remote control interface:
vlc main
> command line
> help
> help
+----[ Remote control commands ]
| add XYZ . . . . . . . . . . . . . . . . . . . . add XYZ to playlist
| enqueue XYZ . . . . . . . . . . . . . . . . . queue XYZ to playlist
| playlist . . . . . . . . . . . . . .show items currently in playlist
| search [string] . . search for items in playlist (or reset search)
| sort key . . . . . . . . . . . . . . . . . . . . . sort the playlist
| sd [sd] . . . . . . . . . . . . . show services discovery or toggle
| play . . . . . . . . . . . . . . . . . . . . . . . . . . play stream etc
To exit the vlc command line, type shutdown and press enter:
etc
[0xb7212ee4] main input error: Your input can't be opened
[0xb7212ee4] main input error: VLC is unable to open the MRL 'file:///home/jill/main'. Check the log for details.
shutdown
Shutting down.[0x831797c] [rc] lua interface: Requested shutdown.
Bye-bye!
jill@host:~$
https://wiki.videolan.org/VLC_command-line_help/
jill@host:~$ vlc
VLC media player 1.1.4 The Luggage (revision exported)
Blocked: call to unsetenv("DBUS_ACTIVATION_ADDRESS")
Blocked: call to unsetenv("DBUS_ACTIVATION_BUS_TYPE")
[0x8723c24] main interface error: no suitable interface module
[0x86778fc] main libvlc error: interface "globalhotkeys,none" initialization failed
[0x86778fc] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
[0x8723c24] [rc] lua interface: Listening on host "*console".
VLC media player 1.1.4 The Luggage
Remote control interface initialized. Type `help' for help.
> help
+----[ Remote control commands ]
| add XYZ . . . . . . . . . . . . . . . . . . . . add XYZ to playlist
| enqueue XYZ . . . . . . . . . . . . . . . . . queue XYZ to playlist
| playlist . . . . . . . . . . . . . .show items currently in playlist
| search [string] . . search for items in playlist (or reset search)
| sort key . . . . . . . . . . . . . . . . . . . . . sort the playlist
| sd [sd] . . . . . . . . . . . . . show services discovery or toggle
| play . . . . . . . . . . . . . . . . . . . . . . . . . . play stream
| stop . . . . . . . . . . . . . . . . . . . . . . . . . . stop stream
| next . . . . . . . . . . . . . . . . . . . . . . next playlist item
| prev . . . . . . . . . . . . . . . . . . . . previous
| seek X . . . . . . . . . . . seek in seconds, for instance `seek 12'
| pause . . . . . . . . . . . . . . . . . . . . . . . . toggle pause
| fastforward . . . . . . . . . . . . . . . . . . set to maximum rate
| rewind . . . . . . . . . . . . . . . . . . . . . set to etc
| volume [X] . . . . . . . . . . . . . . . . . . set/get audio volume
| volup [X] . . . . . . . . . . . . . . . .raise audio volume X steps
| voldown [X] . . . . . . . . . . . . . . lower audio volume X steps
| adev [X] . . . . . . . . . . . . . . . . . . . .set/get audio device
| achan [X] . . . . . . . . . . . . . . . . . .set/get audio channels
| atrack [X] . . . . . . . . . . . . . . . . . . . set/get audio track
| vtrack [X] . . . . . . . . . . . . . . . . . . . set/get video track
| vratio [X] . . . . . . . . . . . . . . . .set/get video aspect ratio
| vcrop, crop [X] . . . . . . . . . . . . . . . . set/get video crop
| vzoom, zoom [X] . . . . . . . . . . . . . . . . set/get video zoom
| snapshot . . . . . . . . . . . . . . . . . . . . take video snapshot
| strack [X] . . . . . . . . . . . . . . . . . set/get subtitles track
|
| description . . . . . . . . . . . . . . . . . .describe this module
| help, ? [pattern] . . . . . . . . . . . . . . . . . .a help message
| longhelp [pattern] . . . . . . . . . . . . . . a longer help message
| logout . . . . . . . . . . . . . . exit (if in a socket connection)
| quit . . . . . . . . quit VLC (or logout if in a socket connection)
| shutdown . . . . . . . . . . . . . . . . . . . . . . . .shutdown VLC
+----[ end of help ]
>
> quit
Shutting down.[0x8723c24] [rc] lua interface: Requested shutdown.
Bye-bye!
> jill@host:~$
Virtual Private Network VPN
see lansudo.txt
To start open the local VPN network:
service openvpn start
name@postbox22:~$ service openvpn start
Failed to start openvpn.service: Unit openvpn.service not found.
name@postbox22:~$
or
name@postbox22:~$ sudo systemctl start openvpn@server.service
Failed to start openvpn@server.service: Unit openvpn@server.service not found.
name@postbox22:~$
To troubleshoot errors with exim4, mail, ufw, ftp and some other programs, look in the directory called /var/log/ and open the log file for the program. Read the error messages logged in the file. Log filenames end in log.
name@postbox22:~$ ls /var/log/
alternatives.log dpkg.log.1 mail.err ufw.log.2.gz
alternatives.log.1 exim4 mail.err.1 unattended-upgrades
apt faillog mail.log upstart
auth.log fontconfig.log mail.log.1 vsftpd.log
auth.log.1 fsck speech-dispatcher vsftpd.log.1
auth.log.2.gz gpu-manager.log syslog wtmp
auth.log.3.gz hp syslog.1 wtmp.1
auth.log.4.gz installer syslog.2.gz Xorg.0.log
bootstrap.log kern.log syslog.3.gz Xorg.0.log.old
btmp kern.log.1 syslog.4.gz Xorg.1.log
btmp.1 kern.log.2.gz syslog.5.gz Xorg.1.log.old
cups kern.log.3.gz syslog.6.gz Xorg.2.log
dist-upgrade kern.log.4.gz syslog.7.gz Xorg.2.log.old
dmesg lastlog ufw.log
dpkg.log lightdm ufw.log.1
name@postbox22:~$
In the system, network, vpn connection, configuration settings gui, there is an option NT domain. NT is Microsoft Windows. So leave that field blank.
Turn VPN off. Setup a LAN instead.
The network program called OpenVPN virtual private network uses Symmetric Key Encryption and Public Key Encryption. Do not use that sort of encryption for this local network. The program 'openvpn' is currently not installed. You can install it by typing:
sudo apt install openvpn
name@postbox22:~$
See also https://protonvpn.com/download-linux
A virtual private network VPN uses port 443.
A local area network LAN uses port 22.
An external gateway network interface is on the internet and uses an external IP address.
name@postbox22:~$ openvpn
Do not set up a VPN. Set up a local area LAN network.
To send WOL Magic Packets under Linux, see wakeonlanhow.txt
Uncomplicated Firewall ufw is the firewall used here. It is the default with Ubuntu.
To show how the local firewall is working, run this ufw command:
sudo ufw status verbose
user:~$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
user:~$
Ufw is enabled and that is its current set of rules.
Uncomplicated Firewall ufw shows that incoming email messages are denied.
To show usage commands for ufw:
ufw -help
user:~$ ufw -h
ERROR: Invalid syntax
Usage: ufw COMMAND
Commands:
enable enables the firewall etc list of all commands.
user:~$
See https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands
To allow the computer firewall to receive on a particular port, run ufw to add a rule with an allow arguement.
sudo ufw allow ipnumber
user:~$ sudo ufw allow 25
Rule added
Rule added (v6)
user:~$
There the port number is 25.
To delete a rule changed in UFW, run ufw delete followed by the rule.
sudo ufw delete allow from ipnumber
user:~$ sudo ufw delete allow 25
[sudo] password for user:
Rule deleted
Rule deleted (v6)
user:~$
Web servers, like Apache, listen for requests on HTTP and HTTPS ports 80 and 443.
To allow all incoming connections to HTTP and HTTPS ports 80 and 443:
$ sudo ufw allow proto tcp from any to any port 80,443
That is for TCP protocol.
To allow all network connections that come from a particular IP address:
sudo ufw allow from ipaddress
Type the IPnumber instead of ipaddress.
By default UFW blocks all external access unless specifically allowed.
The in parameter tells ufw to apply the rule only for incoming connections, and the on eth0 parameter specifies that the rule applies only for the eth0 interface.
To block and deny an organisation from entering through the firewall:
Here the IP address is that of Symantec.com.
user:~$ sudo ufw deny from 52.13.171.212
Rule added
user:~$
To reload firewall:
ufw reload
To reset firewall to its default settings:
ufw reset
This also disables the firewall until the enable command is run.
To enable the firewall:
ufw enable
To fully disable the firewall so that it does not restart on rebooting computer:
ufw disable
To list show which profiles are currently available, run:
sudo ufw app list
user:~$ sudo ufw app list
Available applications:
CUPS
Postfix
Postfix SMTPS
Postfix Submission
user:~$
To enable a UFW application profile, run ufw allow followed by the name of the application profile.
ufw allow profilename
Put "quotes" around any profile name of more than one word, like "Postfix SMTPS"
The following command will allow all incoming connections to Postfix.
sudo ufw allow "Postfix SMTPS"
user:~$ sudo ufw allow "Postfix SMTPS"
[sudo] password for user:
Rule added
Rule added (v6)
user:~$
To open the user manual for UFW:
man ufw
To block port 53 on Ubuntu for TCP protocol:
ufw deny 53/tcp
To allow connections through the firewall from a remote IP address:
ufw allow from remoteIPnumber to localIPnumber
ufw allow from 152.167.2.54
To block all network connections that come from a specific IP address:
sudo ufw deny from ipnumber
In this example here connections to Cloudbad are to be blocked.
To investigate Cloudbad and find its IP address and what port it uses, then deny it access through the firewall: -
sudo ufw deny from 231.31,124.123
IP-Lookup
Retrieve the IP address associated with a web site:
Domain Name: Cloudbad.com
Lookup...
Cloudbad.com
The IP address associated with Cloudbad.com is :
231.31,124.123
Lookup an IP address :
Lookup... [ list ]
IP addresses can be entered using
IPv4 or IPv6 address format.
Help »
IP : 231.31,124.123 Neighborhood
Host : ?
Country : United States
user:~$ ping 231.31,124.123
PING 231.31,124.123 (231.31,124.123) 56(84) bytes of data.
64 bytes from 231.31,124.123: icmp_seq=1 ttl=60 time=16.3 ms etc
64 bytes from 231.31,124.123: icmp_seq=5 ttl=60 time=16.8 ms
^C
--- 231.31,124.123 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 16.272/16.725/17.404/0.418 ms
user:~$
user:~$ wget 231.31,124.123
--2022-11-06 14:50:32-- http://231.31,124.123/
Connecting to 231.31,124.123:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2022-11-06 14:50:32 ERROR 403: Forbidden.
user:~$
Port 80 - HTTP is for normal web browsing and also for a proxy
Cloudbad uses port 80. Apache also uses port 80.
The name and IP address in that example are not real.
wes7@wes7-ID:~$ whois 231.31,124.123
No whois server is known for this kind of object.
wes7@wes7-ID:~$
How to use Woof to share files on a Linux local network.
see also woof.txt
To install woof:
name@postbox22:~$ woof
The program 'woof' is currently not installed. You can install it by typing:
sudo apt install woof
name@postbox22:~$ sudo apt-get install woof
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
woof
0 to upgrade, 1 to newly install, 0 to remove and 0 not to upgrade.
Need to get 9,174 B of archives.
After this operation, 33.8 kB of additional disk space will be used.
Get:1 http://au.archive.ubuntu.com/ubuntu xenial/universe amd64 woof all 20091227-2.1 [9,174 B]
Fetched 9,174 B in 0s (15.2 kB/s)
Selecting previously unselected package woof.
(Reading database ... 175264 files and directories currently installed.)
Preparing to unpack .../woof_20091227-2.1_all.deb ...
Unpacking woof (20091227-2.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up woof (20091227-2.1) ...
To run woof:
name@postbox22:~$ woof
Now serving on http://192.168.1.100:8080/
Copy that web address.
Start Firefox or another web browser.
Paste the web address into the browser field and press enter.
Then see on the terminal screen a line like
192.168.1.100 - - [12/Jun/2022 18:27:29] "GET /- HTTP/1.1" 200 -
and a command prompt.
To check if ports are open for woof:
nmap -sT -O localhost
The program 'nmap' is currently not installed. You can install it by typing:
sudo apt install nmap
name@postbox22:~$
To send a file in the current working directory to another user on the network:
woof filename.ext
To send copies of the file so that more than one user can download it, type a -c 3 option, where the number is how many copies you are sending.
woof -c 2 filename.txt
Any type of file can be sent, like .doc, .pdf, .jpg, mp3 or whatever.
To send a directory of files:
woof directoryname
Woof will automatically compress the directory into a tar.gz file called directoryname.tar.gz
To send a directory of files as a zip file:
woof -Z directoryname
To send a directory without compressing files, type -u for uncompressed:
woof -u directoryname
To receive a file from another user on the network:
First send woof to them.
To send woof to other users on the local network:
woof -s
name@postbox22:~$ woof -s
Now serving on http://192.168.1.100:8080/
Command line.
^C
name@postbox22:~$
Press ctrl-c to cancel.
user on Glite3 did connect to the woof http address but the web page was empty, blank, as no file had been sent.
If a user cannot connect with the browser and sees a cannot connect message, wait and try again later as another user may be connected.
If a user connects to a blank page at woof address, a file may not have been sent or another user may have taken it.
XXD - To make a hex dump of computer data, run an xxd command:
username:/$ xxd
quit
exit
^C
username:/$
In computing, a hex dump is a hexadecimal view of computer data, from memory or from a computer file or storage device. Looking at a hex dump of data is usually done in the context of either debugging, reverse engineering or digital forensics.
xxd, or xxd.exe, is software which can make hexdumps.
The xxd command in Linux lets you create a hexdump or even do the reverse.
xxd creates a hex dump of a given file or standard input. It can also convert a hex dump back to its original binary form. Like
uuencode(1) and uudecode(1) it allows the transmission of binary data in a `mail-safe' ASCII representation, but has the advantage
of decoding to standard output. Moreover, it can be used to perform binary file patching.
username:/$ xxd --help
Usage:
xxd [options] [infile [outfile]]
or
xxd -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]
Options:
-a toggle autoskip: A single '*' replaces nul-lines. Default off.
-b binary digit dump (incompatible with -ps,-i,-r). Default hex.
-c cols format octets per line. Default 16 (-i: 12, -ps: 30).
-E show characters in EBCDIC. Default ASCII.
-e little-endian dump (incompatible with -ps,-i,-r).
-g number of octets per group in normal output. Default 2 (-e: 4).
-h print this summary.
-i output in C include file style.
-l len stop after octets.
-o off add to the displayed file position.
-ps output in postscript plain hexdump style.
-r reverse operation: convert (or patch) hexdump into binary.
-r -s off revert with added to file positions found in hexdump.
-s [+][-]seek start at bytes abs. (or +: rel.) infile offset.
-u use upper case hex letters.
-v show version: "xxd V1.10 27oct98 by Juergen Weigert".
username:/$
To convert change a text file into hex:
xxd filename.txt
See output like
output:
00000000: 4e6f 2e7c 436f 756e 7472 797c 5965 732f No.|Country|Yes/
00000010: 4e6f 0a30 317c 496e 6469 617c 590a 3032 No.01|India|Y.02
00000020: 7c55 537c 590a 3033 7c41 7573 7472 616c |US|Y.03|Austral
00000030: 6961 7c etc
To convert only specific lines of a file into hex, use the -s option with a line number:
xxd -s 0x30 filename.txt
That converts from line 3 onwards.
To limit the hex ouput to a specific length, use the -l option with a line number:
xxd -l 0x30 filename.txt
To change the text into binary digits, a binary dump, use the -b option:
xxd -b filename.txt
See ouput in 1s and 0s.
For help:
xxd -h
Linux Zip commands deleted archive files by mistake, several times. See below. The mistake was that the recursive -r option was not used. So Zip only zipped the folder without the files in it. Unzip then overwrote the empty folder onto the original folder and deleted all the files in it.
Zip roller gui and file manager did the same zip job easily without failure. Zip archives made in Terminal with Zip can be open with Roller and extracted without damaging or losing data. Zips extracted with Roller gui can be open and extracted from using Zip in Terminal.
To zip encrypt a directory of files: -
In Terminal change to the directory holding the subdirectory of files.
localuser:~$ cd Pictures/
localuser:~/Pictures$
localuser:~/Pictures$ ls
Webcam zip2 zip2bac
Here the folder called zip2 is to be encrypted into a zip archive file called zip3.zip . Options here are -e for encrypt and -r for recursively encrypt the folder and the files in it.
localuser:~/Pictures$ zip -er zip3.zip zip2
Type a zip password different from the administration password.
Enter password:
Verify password:
adding: zip2/ (stored 0%)
adding: zip2/archive/ (stored 0%)
adding: zip2/archive/folder1/ (stored 0%)
adding: zip2/archive/folder1/document1 (stored 0%)
adding: zip2/archive/folder2/ (stored 0%)
adding: zip2/archive/folder2/document2 (stored 0%)
adding: zip2/archive/folder/ (stored 0%)
adding: zip2/archive/folder/document0 (stored 0%)
adding: zip2/archive/folder3/ (stored 0%)
adding: zip2/archive/folder3/document3 (stored 0%)
adding: zip2/archive/folder4/ (stored 0%)
adding: zip2/archive/folder4/document4 (stored 0%)
Stored 0% means the files were stored without being compressed, 0 being the defualt.
localuser:~/Pictures$ ls
Webcam zip2 zip2bac zip3.zip
Before unzipping that new archive, rename the original folder so that it cannot be overwritten.
localuser:~/Pictures$ mv zip2 zip3
The move mv command renamed zip2 as zip3.
localuser:~/Pictures$ ls
Webcam zip2bac zip3 zip3.zip
Next unzip the zip2 files in zip3.zip.
localuser:~/Pictures$ unzip zip3.zip
Archive: zip3.zip
creating: zip2/
creating: zip2/archive/
creating: zip2/archive/folder1/
[zip3.zip] zip2/archive/folder1/document1 password:
extracting: zip2/archive/folder1/document1
creating: zip2/archive/folder2/
extracting: zip2/archive/folder2/document2
creating: zip2/archive/folder/
extracting: zip2/archive/folder/document0
creating: zip2/archive/folder3/
extracting: zip2/archive/folder3/document3
creating: zip2/archive/folder4/
extracting: zip2/archive/folder4/document4
localuser:~/Pictures$
Folder zip2 with its document files have been extracted from the zip archive.
localuser:~/Pictures$ ls
Webcam zip2 zip2bac zip3 zip3.zip
localuser:~/Pictures$ ls zip2
archive
localuser:~/Pictures$ ls zip2/archive/
folder folder1 folder2 folder3 folder4
localuser:~/Pictures$
localuser:~/Pictures$ ls zip2/archive/folder4/
document4
localuser:~/Pictures$
There is one document in each folder.
To unzip a zip archive without overwriting any folders or files in the original folder, use the -n option to never overwrite existing files.
localuser:~/Pictures$ unzip -n zip3.zip
Archive: zip3.zip
[zip3.zip] zip2/archive/folder1/document1 password:
localuser:~/Pictures$
localuser:~/Pictures$ ls zip2/archive/folder1
document1
localuser:~/Pictures$
To keep the zipped files private, run the remove -rm command with the recursive -r option to delete the original folder of files.
localuser:~/Pictures$ rm -r zip2
localuser:~/Pictures$ ls
Webcam zip2bac zip3 zip3.zip
localuser:~/Pictures$
In that example, also remove folders zip2back and zip3, leaving the private zip3.zip.
To rename a folder, run the move mv command:
Linux zip will not recognise foldernames or filenames with a blank space in them.
localuser:~/Pictures$ ls
folder Untitled Folder 3 Webcam
Untitled Folder 2 Untitled Folder 4 ziptest
localuser:~/Pictures$ mv UntitledFolder2 folder2
localuser:~/Pictures$ mv UntitledFolder3 folder3
localuser:~/Pictures$ mv UntitledFolder4 folder4
localuser:~/Pictures$ ls
folder folder2 folder3 folder4 Webcam ziptest
localuser:~/Pictures$
To zip, compress and encrypt a folder directory with files in it:
zip -e zipname.zip directoryname
Change to the directory which holds the subdirectory holding the files to be zipped.
Here the subdirectory is in the Pictures directory.
localuser:~$ ls
Chess examples.desktop norconnex Public Videos Desktop Documents Pictures scripts
Downloads Music Programs Templates
localuser:~$ cd Pictures
localuser:~/Pictures$ ls
folder folder2 folder3 folder4 Webcam ziptest
localuser:~/Pictures$
localuser:~/Pictures$ zip -e folder.zip folder
Enter password:
Verify password:
adding: folder/ (stored 0%)
localuser:~/Pictures$ ls
folder folder2 folder3 folder4 folder.zip Webcam ziptest
localuser:~/Pictures$
The encrypt -e option asks for a password twice. This verifies the password so that a typing error does not stop you opening the zip file.
To delete remove the original folder left unencrypted:
First delete all the files in the folder.
localuser:~/Pictures$ rm folder/*
localuser:~/Pictures$ ls folder
Then delete the empty folder.
localuser:~/Pictures$ rmdir folder
localuser:~/Pictures$ ls
folder2 folder3 folder4 folder.zip Webcam ziptest
localuser:~/Pictures$
To unzip a compressed encrypted file:
unzip zipname.zip
or unzip folder.zip
localuser:~/Pictures$ unzip folder.zip
Archive: folder.zip
creating: folder/
localuser:~/Pictures$ ls
folder folder2 folder3 folder4 folder.zip Webcam ziptest
localuser:~/Pictures$
The unzipped files are supposed to be in the folder called folder but have been deleted by mistake. Check * command above.
To update a zip archive file with new or changed files in it:
Unzip the zip file. Change edit files in it, in the unzipped folder, add more files or delete files.
Rezip the folder to replace the old zip of the same name.
zip -e zipname.zip foldername
localuser:~/Pictures$ zip -e folder.zip folder
Enter password:
Verify password:
updating: folder/ (stored 0%)
localuser:~/Pictures$
To check for errors in zip naming:
localuser:~/Pictures$ zip folder
zip error: Nothing to do! (folder.zip)
localuser:~/Pictures$
That error message means the zip command is typed wrongly. The right command looks like
zip -e zipname.zip foldername
where the folder is the one to be zipped and the zipname is the name you give to the zip archive file.
Change to the directory which hold the zipped files.
eg $ cd Pictures.
In that directory run the command zip directoryname
zip directoryname
Run the list command:
$ ls directoryname
Path ./ means current working directory but it is not needed because you are already in the current directory.
ls ./folder/
The / ending is not needed either for the list command.
ls ~/folder/
Path ~/ means home directory but the zip file is not in the home directory. It is in ~/Pictures. That path does not need to be shown as you have changed to the Pictures directory.
To show Zip help:
zip -h2
Zip options include:
-f refresh only the changed files in the zip archive
-u update only changed or new files in the archive
-e encrypt
-n don't compress files with these suffixes
-0 the zero means to only store the files without compressing them. Option -0 is usually not needed as zero compression is the default.
To zip only one type of file in the current directory:
In Terminal, change to the directory containing the mixed files. Here only sound files are to be zipped.
zip -0 archive.zip *.mp3
The zero means no compression. The wildcard * here means all files with names ending in .mp3 .