Tag: Commands

Create a file in Linux

Create a file with touch command

To create a new file, use touch command followed by the name of the file-

This should create a empty file.

touch thirdfile.txt

To create multiple files using touch command-

touch thirdfile-1.txt thirdfile-2.txt

Create a file with cat command

To create a new file with cat command use redirection operator followd by file name.

This will allow to add content to the file

cat > fourthfile.txt

Cratea a file using echo command

To create a new file using echo command use redirection operator followed by file name will create empty file or add content before redirection operator to add content while creating a file.

echo "This is fifth file." > fifthfile.txt

Create a empty file with echo command

echo > sixthfile.txt

Linux File Types

Everything in Linux is file

There are following type of files-

Regular files – Images/scripts/configuration and Data files

Directory – Type of files which saves other files and directories

Special files – have other types

  • Character Files – Represent devices – like Mouse and keyboards
  • Block Files – Represent block devices that writes data in chunk to the devices like HDD and RAM
  • Links – Hard links and Soft Links
  • Socket Files – enables the commnuication between 2 process
  • Named Pipes – passes data from one process to another

Use file command to get the file type-

file <<filename>>

Use ls -ld command to get the file type-

ls -ld firstfile.txt

First character represents the file type

IdentifierFile Type
dDirectory
Regular File
cCharacter Device
lLin
sSocket File
pPipe
bBlock Device

Filesystem Hierarchy

/- Root Partition

/opt – any third party program should be put in this directory

/mnt- mounts the file system from external network temporary to this folder

/tmp- copy any temporary files to this location

/media – copy any media files in this folder

/dev – contains the file character device file like external devices like mouse and keyboard

/bin – basic programs and binaries are located in this directory

/etc – configuration files

/lib and /lib64 – contains shared libraries

/usr – user related data reside in this folder

/var – system writes data such as logs

Linux Runlevels

A runlevel is a categorization number that determines what services are started and
what services are stopped

Runlevel #NameDescription
0HaltAll services are shut down and the server is stopped
1Single User ModeThe root account is automatically logged in to the server and other users cannot log in to the server
2Multiuser ModeUsers can log in to the server through CLI and network service are not started
3Extended Multiuser ModeUsers can log in to the server through CLI and network service are started
4User DefinedUser can cusomize the runlevel
5Graphical ModeUser can log in through CLI and GUI with network services started
6RebootThe server is rebooted

Check the current runlevel use following command-

runlevel

To see the default target

systemctl get-default

To change the default target use following command

systemctl set-default multi-user.target