Linux Flashcards

1
Q

you try to delete a file and get “access denied”, what do you do?

A

This happens because you don’t own the directory, it is owned by ‘root’ and the ‘root’ group. So to delete it you can either changing the ownership and then delete it (here you elevate your rights and become ‘root’ for taking the ownership):

sudo chown $USER:$USER ./shadi
rm -r ./shadi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are some important directories in a fresh new linux installation?

A

/ — The Root Directory
Everything on your Linux system is located under the / directory, known as the root directory. You can think of the / directory as being similar to the C:\ directory on Windows — but this isn’t strictly true, as Linux doesn’t have drive letters. While another partition would be located at D:\ on Windows, this other partition would appear in another folder under / on Linux.

/bin — Essential User Binaries
The /bin directory contains the essential user binaries (programs) that must be present when the system is mounted in single-user mode. Applications such as Firefox are stored in /usr/bin, while important system programs and utilities such as the bash shell are located in /bin. The /usr directory may be stored on another partition — placing these files in the /bin directory ensures the system will have these important utilities even if no other file systems are mounted. The /sbin directory is similar — it contains essential system administration binaries.
/boot — Static Boot Files
The /boot directory contains the files needed to boot the system — for example, the GRUB boot loader’s files and your Linux kernels are stored here. The boot loader’s configuration files aren’t located here, though — they’re in /etc with the other configuration files.

/cdrom — Historical Mount Point for CD-ROMs
The /cdrom directory isn’t part of the FHS standard, but you’ll still find it on Ubuntu and other operating systems. It’s a temporary location for CD-ROMs inserted in the system. However, the standard location for temporary media is inside the /media directory.

/dev — Device Files
Linux exposes devices as files, and the /dev directory contains a number of special files that represent devices. These are not actual files as we know them, but they appear as files — for example, /dev/sda represents the first SATA drive in the system. If you wanted to partition it, you could start a partition editor and tell it to edit /dev/sda.

/etc — Configuration Files
The /etc directory contains configuration files, which can generally be edited by hand in a text editor. Note that the /etc/ directory contains system-wide configuration files — user-specific configuration files are located in each user’s home directory.

/home — Home Folders
The /home directory contains a home folder for each user. For example, if your user name is bob, you have a home folder located at /home/bob. This home folder contains the user’s data files and user-specific configuration files. Each user only has write access to their own home folder and must obtain elevated permissions (become the

/lib — Essential Shared Libraries
The /lib directory contains libraries needed by the essential binaries in the /bin and /sbin folder. Libraries needed by the binaries in the /usr/bin folder are located in /usr/lib.

/lost+found — Recovered Files
Each Linux file system has a lost+found directory. If the file system crashes, a file system check will be performed at next boot. Any corrupted files found will be placed in the lost+found directory, so you can attempt to recover as much data as possible.

/media — Removable Media

/mnt — Temporary Mount Points
Historically speaking, the /mnt directory is where system administrators mounted temporary file systems while using them. For example, if you’re mounting a Windows partition to perform some file recovery operations, you might mount it at /mnt/windows. However, you can mount other file systems anywhere on the system.

/opt — Optional Packages
The /opt directory contains subdirectories for optional software packages. It’s commonly used by proprietary software that doesn’t obey the standard file system hierarchy — for example, a proprietary program might dump its files in /opt/application when you install it.

/proc — Kernel & Process Files
The /proc directory similar to the /dev directory because it doesn’t contain standard files. It contains special files that represent system and process information.

/root — Root Home Directory
The /root directory is the home directory of the root user. Instead of being located at /home/root, it’s located at /root. This is distinct from /, which is the system root directory.

/run — Application State Files
The /run directory is fairly new, and gives applications a standard place to store transient files they require like sockets and process IDs. These files can’t be stored in /tmp because files in /tmp may be deleted.

/sbin — System Administration Binaries
The /sbin directory is similar to the /bin directory. It contains essential binaries that are generally intended to be run by the root user for system administration.

/tmp — Temporary Files
Applications store temporary files in the /tmp directory. These files are generally deleted whenever your system is restarted and may be deleted at any time by utilities such as tmpwatch.

/usr — User Binaries & Read-Only Data
The /usr directory contains applications and files used by users, as opposed to applications and files used by the system. For example, non-essential applications are located inside the /usr/bin directory instead of the /bin directory and non-essential system administration binaries are located in the /usr/sbin directory instead of the /sbin directory. Libraries for each are located inside the /usr/lib directory. The /usr directory also contains other directories — for example, architecture-independent files like graphics are located in /usr/share.

/var — Variable Data Files
The /var directory is the writable counterpart to the /usr directory, which must be read-only in normal operation. Log files and everything else that would normally be written to /usr during normal operation are written to the /var directory. For example, you’ll find log files in /var/log.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

you just downloaded a file such as a script, what will you have to do to run it?

A

There are two ways to run a shell script in Linux. You can use:

bash script.sh
Or you can execute the shell script like this:

./script.sh
That maybe simple, but it doesn’t explain a lot. Don’t worry, I’ll do the necessary explaining with examples so that you understand why a particular syntax is used in the given format while running a shell script.

I am going to use this one line shell script to make things as uncomplicated as possible

84

First you might need to give the .sh file permission to execute. chmod +x file.sh, then you can execute it with ./file.sh.

You can also right-click on the file, select Properties, then select Permissions and then select ‘Allow executing file as program’. Then you double-click the file and select ‘Run in Terminal’ or ‘Run’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how do you find out the hostname of the system you’re on?

A
Open a command-line terminal app (select Applications > Accessories > Terminal), and then type:
hostname
OR
hostnamectl
OR
cat /proc/sys/kernel/hostname
Press [Enter] key
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how do you reboot a linux system right now?

A

$ sudo shutdown -r now
To power down immediately:

$ sudo shutdown -P now

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what determines how many inodes you have on a linux system?

A

The Elements of a File System
By definition, a file system needs to store files, and they also contain directories. The files are stored within the directories, and these directories can have subdirectories. Something, somewhere, has to record where all the files are located within the file system, what they’re called, which accounts they belong to, which permissions they have, and much more. This information is called metadata because it’s data that describes other data.

In the Linux ext4 file system, the inode and directory structures work together to provide an underpinning framework that stores all the metadata for every file and directory. They make the metadata available to anyone who requires it, whether that’s the kernel, user applications, or Linux utilities, such as ls, stat, and df.

Inodes and File System Size
While it’s true there’s a pair of structures, a file system requires many more than that. There are thousands and thousands of each structure. Every file and directory requires an inode, and because every file is in a directory, every file also requires a directory structure. Directory structures are also called directory entries, or “dentries.”

Each inode has an inode number, which is unique within a file system. The same inode number might appear in more than one file system. However, the file system ID and inode number combine to make a unique identifier, regardless of how many file systems are mounted on your Linux system.

ADVERTISEMENT

Remember, in Linux, you don’t mount a hard drive or partition. You mount the file system that’s on the partition, so it’s easy to have multiple file systems without realizing it. If you have multiple hard drives or partitions on a single drive, you have more than one file system. They might be the same type—all ext4, for example—but they’ll still be distinct file systems.

All inodes are held in one table. Using an inode number, the file system easily calculates the offset into the inode table at which that inode is located. You can see why the “i” in inode stands for index.

The variable that contains the inode number is declared in the source code as a 32-bit, unsigned long integer. This means the inode number is an integer value with a maximum size of 2^32, which calculates out to 4,294,967,295—well over 4 billion inodes.

That’s the theoretical maximum. In practice, the number of inodes in an ext4 file system is determined when the file system is created at a default ratio of one inode per 16 KB of file system capacity. Directory structures are created on the fly when the file system is in use, as files and directories are created within the file system.

There’s a command you can use to see how many inodes are in a file system on your computer. The -i (inodes) option of the df command instructs it to display its output in numbers of inodes.

We’re going to look at the file system on the first partition on the first hard drive, so we type the following:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly