The use of the Linux kernel has resulted in a wide range of operating systems, known as Linux distributions, which are used on a variety of devices including personal computers, servers, and smartphones. Linux is widely respected for its security features and is often used in enterprise environments.
The Linux operating system gets its name from the Linux kernel, which was developed in 1991 by Linus Torvalds. In addition to the kernel, the system also includes a variety of utilities and libraries that are derived from the GNU operating system. The GNU operating system was first announced in 1983 by Richard Stallman, and its contributions to the Linux system have led to the alternate name GNU/Linux being used to refer to the operating system as a whole. It is widely supported by major corporations such as Dell, Hewlett-Packard, IBM, Novell, Oracle Corporation, Red Hat, Sun Microsystems, and even Microsoft. These companies provide support, services, and resources for businesses and individuals using Linux in their operations.
There are two main ways to remotely access a Linux server: using a terminal application and using an SFTP client. Using a terminal application, such as Putty, is the recommended method for accessing a Linux server, as it allows you to enter commands and interact with the server directly.
Install and start the Putty application.
Alternatively, you can use an SFTP client, such as WinScp, to transfer files to and from the Linux server. This is a good option if you don’t need to enter commands or interact with the server directly. Simply start the SFTP client, enter the connection details for the Linux server, and you will be able to transfer files to and from the server.
To connect to a Linux server using tools like Putty or WinSCP, you will need to ensure that you have the necessary credentials and access permissions. One thing to keep in mind is that the server may use Secure Shell (SSH) keys for secure identification. If you are connecting to a server for the first time, you may be prompted to accept the server’s SSH key. It is important to accept the key and store it locally on your computer to ensure a secure connection. If you have any issues or questions about SSH keys or connecting to the server, it is always a good idea to reach out to the server administrator or your IT support team for assistance.
/
(slash, or forward slash)FileName
is not the same as afilename
.
(dot) is a hidden file or directoryThe passwd
command allows you to change your password:
• Enter your old password (when not a root user)
• Enter your required new password
• Enter your required new password again
cd
command to move between directories, and the ls
command to view the contents of a directory.nano
, vi
, or emacs
to create and edit text files in the terminal.apt
or yum
to install new software and update existing software.ps
, top
, and kill
to view and control processes running on the system.scp
and sftp
to transfer files between systems.Look at directory contents | ls |
Change directory | cd |
Find files | find |
Copy and move files | cp and mv |
Remove files | rm |
Create directories | mkdir |
Remove directories | rmdir (dir must be empty) |
To determine the type of a file | file |
Dump a file to the screen | cat |
Page thru a file | less |
Search in a file | grep |
Tail a file | tail |
Count words or lines in a file | wc or wc –l |
View activity on the server | ps and top |
ls
Shows directory contentsls -a
Shows all directory contents (including hidden files starting with a dotls -l
Shows directory contents as a list with extra infols -la
Shows all directory contents as listls -lh
Shows directory contents as list, sizes in a readable format (Kb Mb)ls -lt
Shows directory contents as list, ordered by file-change timels -ltr
Shows directory contents as list, ordered by file-change time (reversed, last changed file at the
Example:
$ls -la drwxr-xr-x 1 file_owner owners_group 946 2010-11-11 11:11 filename
Fields explanation
drwxr-xr-x 1 user1 users 946 2010-11-11 11:11 filename
Permissions | NR of Links, Directories | Owner | Group | File Size | Date Modified | Time Modified | File name |
---|---|---|---|---|---|---|---|
d rwx r-x r-- | 1 | user1 | users | 946 | 2010-11-11 | 11:11 | file-name |
Permissions determine who is allowed to access and perform certain actions on a file or directory.
There are three types of permissions:r
= read permissionw
= write permissionx
= execute permission-
= no permission
Permissions – Special indicators:d
= directory-
= regular filel
= symbolic links
= UNIX domain socketp
= named pipec
= character device fileb
= block device file
Examples:
rwx r-x r-- <file-name>
owner: can read, write and execute the file rwx
group: can only read and execute the file r-x
others: can only read the file r--
dr-x --- --- <directory-name>
owner has read and execute access r-x
(x
allows directory browsing)
group and others have no access to the directory --- ---
Directory commands
cd | without a parameter leads you to your home dir |
cd ~ | (with tilde) does the same |
pwd | shows the current directory |
mkdir | lets you create directories |
rmdir | lets you remove a directory (dir must be empty) |
The find command lets you find files
find . – name somename | Find file with name somename starting from current directory |
find /dir – name ‘some*’ | Find file with name starting some with some starting from /dir. Use the quotes! |
find . – iname somename | Find file with name somename starting from current directory, ignoring case of the filename |
The cp command lets you copy files and directories
cp srcfile tgtfile | Copy file ‘srcfile’ to file ‘tgtfile’ |
cp *.log target_dir | Copy all logfiles to directory ‘target_dir’ |
cp one.log two.log target_dir | Copy ‘one.log’ and ‘two.log’ to directory ‘target_dir’ |
cp –R source_dir target_dir | Copy source_dir and all its content to directory target_dir’ |
cp –R source_dir/* target_dir | Copy the content of source_dir to directory ‘target_dir’ |
• The mv command lets you move (and rename) files and directories
mv srcfile tgtfile | Move (rename) file ‘srcfile’ to file ‘tgtfile’ |
mv *.log target_dir | Move all logfiles to directory ‘target_dir’ |
mv one.log two.log target_dir | Move ‘one.log’ and ‘two.log’ to directory ‘target_dir’ |
mv –R source_dir target_dir | Move source_dir and all its content to directory ‘target_dir’ |
mv –R source_dir/* target_dir | Move the content of source_dir to directory ‘target_dir’ |
The rm command lets you delete files
rm logfile.log | Delete a file. |
rm –rf /dir_1 | Deletes all files and directories recursively in directory /dir_1 including. (Attention! Never perform something like this: rm –rf / ). |
The tar command lets you archiving files and directories into a single file, it does not compress them
tar –cvf logs.tar *.log | Archive all log files into logs.tar (no compression yet) |
tar –xvf logs.tar | Unarchive all files from logs.tar |
• The gzip command compresses a file
gzip logs.tar | Compresses logs.tar to logs.tar.gz (removing logs.tar) |
gunzip logs.tar.gz | Decompresses logs.tar.gz to logs.tar (removing logs.tar.gz) |
• Combined (you could combine tar with gzip in one command)
tar –cvzf logs.tar.gz *.log | Packs and compresses all log files into logs.tar.gz |
tar –xvzf logs.tar.gz | Decompresses and unpacks all files from logs.tar.gz |
less – shows the content on your screen and allows you to page through it
grep – searches a file for a string
tail – shows the end of a file
wc – counts words or lines in a file
file – displays the type of a file
cat – dumps the contents of a file on your screen
The less command shows the content on your screen and allows you to page through it
$ less filename
Shows the file content on the screen (scroll using cursors)
– Keys (use thise keys while browsing the file):
• space Next page
• b (char) Previous page
• / Search forwards
• ? Search backwards
• q Quits
The grep command searches for strings in files
grep error logfile.log | Searches for the string ‘error’ in ‘logfile.log’ |
grep –i error logfile.log | Searches case-insensitive for the string ‘error’ in ‘logfile.log’ (so finds Error, eRror and error) |
grep error *.log | Searches for the string ‘error’ in all files ending with .log in the current directory |
The tail command shows the last part of a file
tail -n 50 logfile.log | Shows the last 50 lines of the file ‘logfile.log’ |
tail -f logfile.log | Follows the end of ‘logfile.log’, every line that is appended by another process is shown on your screen (very handy tracking files in real time) |
The wc command counts words or lines in a file
wc -l logfile.log – Count the number of lines in the file ‘logfile.log’
The ps command shows a snapshot of current processes
For continuous information: use top
ps | Show all processes for the current user at the current terminal |
ps -e | Show all processes on the system PID, TTY, TIME and CMD |
ps -ef | Show all processes on the system with extended info UID, PID, PPID, C, STIME, TTY, TIME and CMD |
ps -efH | Show all processes on the system with extended info as a tree UID, PID, PPID, C, STIME, TTY, TIME and CMD |
ps auxf | it’s also cool display |
– UID The user id
– PID The process id
– PPID The parent process id
– C Percentage CPU usage
– STIME Starting time of the process. If the elapsed time is > 24 hours, the starting date
– TTY The terminal that started the process
– TIME The CPU time used
– CMD The executing command
The top command displays active system tasks
Example of output: screen with a header and top-active tasks
$ top 09:49:31 up 41 days, 16:26, 4 users, load average: 0.21, 0.27, 0.23 Tasks: 100 total, 2 running, 98 sleeping, 0 stopped, 0 zombie Cpu(s): 0.9%us, 0.1%sy, 5.3%ni, 93.5%id, 0.1%wa, 0.0%hi, 0.1%si, 0.0%st Mem: 8309568k total, 8215884k used, 93684k free, 233920k buffers Swap: 1052248k total, 70764k used, 981484k free, 504504k cached
us: user cpu time
sy: system cpu time
ni: user nice cpu time
id: idle cpu time
wa: io wait cpu time
hi: hardware irq (servicing hardware interrupts)
si: software irq (servicing software interrupts)
st: steal time (time in involuntary wait by virtual cpu while hypervisor is servicing another processor)
PID | USER | PR | NI | VIRT | RES | SHR | S | %CPU | %MEM | TIME+ | COMMAND |
1946 | user1 | 16 | 0 | 3320 | 1056 | 792 | R | 1 | 0.0 | 0:00.24 | top |
1410 | root | 18 | 0 | 1249m | 180m | 13m | S | 23 | 5.9 | 0:31.85 | rm -rf / |
Columns explained:
PID | The process id |
USER | The user executing the process |
PR | Priority value |
NI | Nice value |
VIRT | Amount of virtual memory used by a task |
RES | The non-swapped physical memory used by a task |
SHR | The amount of shared memory used by a task |
S | Status: D = Uninterruptable sleep, R = Running, S = Sleeping, T = traced or stopped, Z = zombie |
%CPU | Percentage of CPU used |
%MEM | Percentage of physical memory used by a task |
TIME+ | CPU time used by this task since started |
COMMAND | The command that is being executed in the process |
A lot of small commands that all do a single thing combined together they are much more powerful “|” a vertical pipe mark is being used
Examples:
• Count the number of lines in logfile.log that contain the string ‘error’
grep error logfile.log | wc –l
• Count the number of logfiles
ls –l *.log | wc -l
• View a paginated list of logfiles
ls –l *.log | less
• Tail a logfile only showing lines that contain the string ‘error’
tail –f logfile.log | grep error
• Gets a list of active processes Filter lines that contain the string ‘java’ Count the lines
ps –ef | grep –I java | wc -l
Executing programs
• If the program is in the PATH: just enter the program name
# ifconfig
• If the program is not in the path: enter full path + program name
# /sbin/ifconfig
• The current directory is NEVER in the path, use: ./
# cd /sbin # ./ifconfig
• Shell scripts that are executable: just execute as a normal program
# cd /home/myscripts # ls -la -rwxr-xr-x 1 user69 users 0 Nov 11 16:33 myscript.sh # ./myscript.sh
• Shell scripts that are not executable, use: sh
# cd /home/myscripts # ls -la -rw-r--r-- 1 user69 users 0 Nov 11 16:33 myscript.sh # sh myscript.sh
• Check whether the program is in your $PATH
# which ifconfig /sbin/ifconfig
• ctrl+c cancels a running program (most of the time)
• ctrl+d ends a session (as does the exit command)
• screen: (must be installed) Use multiple screens, and keep sessions alive between (dis)connects
while in screen mode:
– ctrl+a c create a new screen (taping order: ctrl+a then release ctrl+a and press “c” button separate)
– ctrl+a switch to screen (keyboard’s numbers)
– screen -wipe shows actual screens
– screen -x connects to detached screen
– ctrl+d end a screen
– ctrl+a esc scroll through a screen (esc ends scrolling)
• man : Asks for the manual page of a command / program e.g. man cp
• which : find out the path of the command
• tab key auto completion
For instance:
taping “cd /home/userone” could be written much faster with help of tab key functionality:
cd /ho[press tab]/use[press tab] – observe that the right existing path will be auto filled up – very handy! use it!
Short Description of the Linux file structure
Filesystems |
Description |
||||||||||||||||||||||
root “/” |
Basic operating system and maintenance tools. The content of this file system should be sufficient to start up the system and perform emergency maintenance and repairs if they were necessary. |
||||||||||||||||||||||
The parts of the root file system are:
|
|||||||||||||||||||||||
/usr |
All commands, libraries, documentation, and other files that do not change during normal operation. This will also contain major applications that come with your Linux distribution, for example Netscape. |
||||||||||||||||||||||
/var |
Files that change: spool directories, log files, lock files, temporary files, and formatted (on use) manual pages. |
||||||||||||||||||||||
/home |
User files (users’ own settings, customization files, documents, data, mail, caches, etc). The contents of this directory should be preserved on an operating system upgrade. ~ (tilde) Is the alias for your home directory ex. cd ~ or cd will lead you to your home directory instead cd /home/your_user |
||||||||||||||||||||||
/proc |
Entirely illusionary files. They do not really exist on the disk and do not take up any space there (although ls -l will show their size). When viewing them, you really access information stored in the memory. It is used to access information about the system. |
MobaXterm is an enhanced terminal application for Windows that provides a wide range of tools and features to help you work with your servers and networks. It includes an X11 server, a tabbed SSH client, and a variety of network tools and utilities. It is a powerful and versatile tool that is perfect for system administrators and IT professionals. You can download MobaXterm here.