List of basic Linux commands
mkdir ==> The mkdir command will allow you to create a directory with the required name
Example: mkdir Narendra ==> This command will create a directory called "Narendra".
rmdir: The rmdir command will delete an empty directory.
- To navigate into the root directory, use cd / ↵
- To navigate to your home directory, use cd ↵ or cd ~ ↵
- To navigate up/back one directory level, use cd .. ↵
- To navigate to the previous directory (or before), use "cd - ↵
- To navigate through multiple levels of a directory at once, specify the full directory path that you want to go to. For example, use "cd home/Narendra/test_scripts/" to go directly to the test_scripts subdirectory.
- As another example, "cd ~/Desktop" will move you to the Desktop subdirectory inside your home directory.
Files related Linux commands
touch file_name.txt ==> create a single file in pwd (present working directory)touch file_name1.txt file_name_2.txt ==> create multiple files in pwd
cat file_name1.txt ==> display the content of the file
find . -name "narendra.txt" ==> Find a file (narendra.txt /any extension-related files) in current and sub-directories
find /home -name *.jpg ==>
Look for all .jpg files (any extension-related files) in the /home and directories below it.
ls -l ==> Displays available files & folders available in pwd with permissions, sizes, date & time
diff ==> Compare the contents of two files line by line
Small clarification: pwd will display the file's path, but readlink -f file_name will display the path name and the file name at a time.
è What is chmod 777?
chmod 777 means granting all permissions to read, write, and execute any file/directory by any user of the system
General Linux commands
Upgrade RHEL OS
ssh username@<IP address> press Enter, enter the password of the remote machine
ssh narendra@10.xx.xx.xx <Enter>
scp file_name.zip root@10.xx.41.xxx:/home/
How to copy a file within the same machine?
cp<space> file_name_to_be_copied<space>path_of _the_directory (where to copy)
How to copy a directory within the same machine?
cp<space> directory_name_to_be_copied<space> -r <space>path_of _the_directory (where to copy)
==============
Syntax: watch [OPTIONS] COMMAND
watch
the command will temporarily clear all of the terminal content and run the provided command at regular intervals. When used without any option watch
will run the specified command every two seconds.Example: 1
In Terminal==> watch date <Enter> by default, every 2 seconds date will update.
==> watch<space> -n <space>5 <space>date (for 5 seconds date will update)
==> watch <space>-n <space>5 <space>-t <space> date
Note: Ctrl+c to exit from it.
Example: 2
watch python log_parser.py
log_parser python will execute continuously.
Linux Keyboard Shortcutsctrl+alt+t ==> To open a terminal in Linux-related OS
ctrl+ Alt +t ==> To open a new terminal window
ctrl+ Shift +t ==> To open the terminal tab
ctrl + a ==> Move the cursor to the beginning of the line
Ctrl + e ==> Move the cursor to the end of the line
ctrl + c ==> To stop/come out / break the currently executing command (In the Terminal)
(if you have typed a long/short command in the terminal, but you don't want to run/ erase it, then you can use Ctrl+C in the Terminal)
ctrl +d ==> to close the current terminal (or) exit ==> logout of the current session.
ctrl +l ==> will clear the terminal screen (or) clear command will clear the terminal screen
ctrl +r ==> Recall the last command that matches the provided characters (handy command)
TAB ==> autofill typing (while typing directory names/file names /commands type starting 2 letters then type TAB )
!! ==> Repeat the last command
ctrl + k ==> cut part of the line after the cursor & add it to the clipboard
ctrl + u ==> cut part of the line before the cursor & add it to the clipboard
ctrl + w ==> cut one word before the cursor & add it to the clipboard
ctrl + y ==> paste from clipboard
ctrl + o ==> Run the previously recalled command (for some Linux flavours only)
ctrl+alt+t ==> To open a terminal in Linux-related OS
ctrl+ Alt +t ==> To open a new terminal window
ctrl+ Shift +t ==> To open the terminal tab
ctrl + a ==> Move the cursor to the beginning of the line
Ctrl + e ==> Move the cursor to the end of the line
ctrl + c ==> To stop/come out / break the currently executing command (In the Terminal)
(if you have typed a long/short command in the terminal, but you don't want to run/ erase it, then you can use Ctrl+C in the Terminal)
ctrl +d ==> to close the current terminal (or) exit ==> logout of the current session.
ctrl +l ==> will clear the terminal screen (or) clear command will clear the terminal screen
ctrl +r ==> Recall the last command that matches the provided characters (handy command)
TAB ==> autofill typing (while typing directory names/file names /commands type starting 2 letters then type TAB )
!! ==> Repeat the last command
ctrl + k ==> cut part of the line after the cursor & add it to the clipboard
ctrl + u ==> cut part of the line before the cursor & add it to the clipboard
ctrl + w ==> cut one word before the cursor & add it to the clipboard
ctrl + y ==> paste from clipboard
ctrl + o ==> Run the previously recalled command (for some Linux flavours only)
How to change hostname in Linux-based machines/servers
Screen tool
screen
tool is a terminal multiplexer. It allows you to create, manage, and maintain
multiple terminal sessions within a single window or SSH session.
commands to use the screen tool:
==============
📁 /etc
— System Configuration Files
-
Purpose: It holds "system-wide configuration files" and shell scripts that are used to boot and initialize system settings.
-
Scope: Affects the entire system (not just one user).
-
Access: Usually requires root/superuser permissions to modify.
🔧 Common Directories & Files in
/etc
Name Description/etc/passwd --> User account information (non-sensitive) /etc/shadow --> Encrypted user passwords (restricted access) /etc/group --> Group account information /etc/fstab --> File system mount points /etc/hostname --> System hostname /etc/hosts --> Static table of IP addresses and names /etc/resolv.conf --> DNS resolver configuration /etc/network/ --> Network interfaces setup (used in Debian-based systems) /etc/systemd/ --> Systemd service and boot config /etc/init.d/ --> Legacy init scripts /etc/cron.* --> Scheduled tasks (cron jobs) /etc/ssh/ --> SSH server and client config /etc/profile --> System-wide shell config for login shells
What is a log file?
A log file is a computer-generated data file that contains information about usage patterns,
activities, and operations within an operating system, application, server or another device.
Log files show whether resources are performing properly and optimally.
What is the purpose of a log file?
Log files are used to record events or activities that occur within a computer system/ application/ program.
Log files serve as a detailed record of what has happened within a system,
which can be used for troubleshooting problems or investigating security incidents.
Example1: let’s assume server crash happened!
then "Log files are used to investigate what happened before server crashed"
Note: In Linux based OS, all log files will be saved at "/var/log/" path
Example2: After system turn ON, if you have faced any problem,
then we need to check in boot.log (available at "/var/log/" )
Python-related commands
====================
python -V(capital V) ==> Displays python 2.7.X version installed on your machine
python3 -V(capital V) ==> Displays python 3.X.X version installed on your machine.
====================
python3 -V(capital V) ==> Displays python 3.X.X version installed on your machine.
No comments:
Post a Comment