Working with Linux files Flashcards
Briefly explain Linux file philosophy
In Linux everything is a file, if it is not a file then it is a process.
Explain three basic file types in Linux
- Ordinary files
Contains data, text or program instructions - Directories
Store both ordinary and special files - Special files
Provide access to hardware such as disk drives
Enables you to access a single file using different file names.
Color that represent directory
Blue
Color that represent compressed archives files
Red
Color that represent text files
White
Color that represent images
Pink
Color that represent links
Cyan
Color that represent devices
Yellow
Color that represent executables
Green
Color that represent broken links
Flashing red
What is the important of using colors to represent file types?
It allows the user to see the file type without using any options to ls
The standard scheme for file type colors
/etc/DIR_COLORS:
What command do we use to find out more about data we are dealing with
file command
i. e #file Tama.txt
ls -l First column
represents file type and permission given on a file
ls -l Second column
Represents number of memory blocks taken by the file or dir
ls -l Third column
Represents owner of the file. The one who created it
ls -l Fourth column
Represents group of the owner
ls -l Fifth column
Represents file size in bytes
ls -l Sixth column
Represents date and time when the file was created or modified last time.
ls -l Seventh column
Represents file or directory name
Identify these character as they are used to indicate file type in ls -l list: - b c d l p s
- : Regular file eg ASCII txt file, bins, exe or hard links
b: Block special file. Block input/output device file eg physical hdd
c : Character special file. Raw input/output device file eg physical hdd
d : Directory containing other files
l : Symbolic link file. Links on regular file
p : Named pipe. Mechanism for IPC
s : Socket used for IPC
. : Invisible file
How do list invisible files in Linux?
By including -a option to ls command
What are the three Linux commands that allows you to view the contents of a file?
- cat
- More
- less
How do you display contents of a file with line numbers?
By adding -b option to cat, more or less
How do you know which shell you are using (2 ways)
Either check the line for your account in /etc/passwd or type the command: echo $SHELL
How do view known shells in Linux system?
cat /etc/shells
How do count total number of lines, words and characters in a file?
wc
Apart from creating a new file, what are some effects of touch command to a file or directory?
It is used to update the access date or modification date of a file or a directory.
How do you make a copy of an existing file?
cp
How do you rename a file?
mv
How do you delete a file?
rm
rm (for multiple files)
Define Directory Tree?
It is a hierarchical structure for organizing files and directories
How do you go back in your home directory or other users?
cd ~ or cd~
How do you go back one level (last dir)?
cd -
How do you see if your home dir has quota system set?
quota -v
Explain two ways of displaying path names
- Absolute
A path name is absolute if it is described in relation to root, so it begin with / always - Relative
Relative path names never begin with /
How do you determine where you are within the file system at anytime?
pwd
How do you list files in a dir?
ls
ls -l /usr/local (for long list)
How do you delete a directory?
rm
How do you define an environmental variables in Linux?
Are variables that are defined for the current shell and are inherited by any child shells or processes.
Environmental variables are used to pass information into processes that are spawned from the shell
What are shell variables?
Are variables that are contained exclusively within the shell in which they were set or defined
The are often used to keep track of ephemeral data, like the CWD
What does printenv command do?
Print all or part of the environment
What does env command do?
Print all exported environment or run a program in a modified environment
What does set command do?
Print the name and value of each shell variable
Briefly describe commonly used variables in Linux
- BASH_VERSION - Holds the version of this instant bash - echo $BASH_VERSION
- HOSTNAME - The name of your computer - $echo HOSTNAME
- HOME - The home directory of current user - $echo $HOME
- PATH - The search path for commands - $PATH
- PS1 - Your prompt settings - $echo PS1
- TERM - Your login terminal type - echo $TERM
- SHELL - Set path to login shell - echo $SHELL