Linux centos командная строка

miranda-zhang / linux.md

Ctrl + C is used to kill a process with signal SIGINT , in other words it is a polite kill .

Ctrl + Z is used to suspend a process by sending it the signal SIGTSTP , which is like a sleep signal, that can be undone and the process can be resumed again.

Ctrl+D: log out of current session, similar to exit.

history | grep «command looking for»

  • Ctrl+R – type to bring up a recent command
  • !! — repeats the last command
  • exit – log out of current session
  • fg in the foreground or bg in the background
  • Ctrl+W – erases one word in the current line
  • Ctrl+U – erases the whole line
sudo groupadd ic-api sudo usermod -g ic-api ic-api 

grep pattern dir — Search for pattern in dir.

-l (or —files-with-matches ) option is used to only print filenames of matching files, and not the matching lines (this could also improve the speed, given that grep stop reading a file at first match with this option).

—include search only files that match the file pattern

grep -ril --include \*.py --include \*.html ".id" 
grep 'pattern1\|pattern2' filename grep -E 'pattern1|pattern2' filename 

Find all instances of file

  • cal – show this month’s calendar
  • uptime – show current uptime
  • w – display who is online
  • whoami – who you are logged in as
  • finger user – display information about user
  • htop — a lightweight text-mode process viewer packed with handy features such as killing processes without entering their PID, displaying full command lines, etc with a colour display

Show number of cores only

grep -c ^processor /proc/cpuinfo 

Show memory and swap usage, show output in gigabytes.

Show the current date and time, in the format of: date+»T»+hour+minute+second+UTC time zone offset

$ date +"%FT%H%M%S%z" 2019-02-19T104943+1100 

show disk usage with human readable unit.

show directory space usage, only one level deep.

One line command to just grep the ip:

ip a | grep "scope global" | grep -Po '(? 

For older version of centOS:

ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '' 

netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

-a, --all Show both listening and non-listening (for TCP this means established connections) sockets. With the --interfaces option, show interfaces that are not up

--numeric , -n Show numerical addresses instead of trying to determine symbolic host, port or user names.

-p, --program Show the PID and name of the program to which each socket belongs.

CentOS 7 netstat, which is part of the package net-tools has been officially deprecated, so you should be using ss (part of the package iproute2 ), going forward.

-l, --listening Display only listening sockets (omitted by default).

-n, --numeric Do not try to resolve service names.

-p, --processes Show process using socket.

-t, --tcp Display TCP sockets.

journalctl -u nginx.service --since today 

Prints the names and values of all currently defined environment variables

Examine the value of a particular variable

The dollar sign $ can actually be used to combine the values of environment variables in many shell commands. For example, the following command can be used to list the contents of the "Desktop" directory within the current user's home directory.

System wide environment variables

sudo -H nano /etc/environment 

It's important to do exact the way above, and not as the root user, as it may cause problems like unable to login. If you use normal sudo to start graphical applications (including editors e.g. gedit), sometimes it results in the configuration files being owned by root, read more about it here.

The only time the file is read is on login, when the PAM stack is activated – specifically pam_env.so, which reads the file.

Logging out and back in would apply the changes – and in fact you must do this if you want all your processes to receive the new environment. All other solutions will only apply the environment to the single shell process, but not to anything you launch through the GUI including new terminal windows.

show which app will be run by default

show the manual for command

  • cd dir - change directory to dir
  • cd – change to home
  • pwd – show current directory
  • mkdir dir – create a directory dir
  • rm file – delete file
  • rm -r dir – delete directory dir
  • rm -f file – force remove file
  • rm -rf dir – force remove directory dir *
  • cp file1 file2 – copy file1 to file2
  • cp -r dir1 dir2 – copy dir1 to dir2; create dir2 if it doesn't exist
  • mv file1 file2 – rename or move file1 to file2 if file2 is an existing directory, moves file1 into directory file2
  • touch file – create or update file
  • cat > file – places standard input into file
  • more file – output the contents of file
  • head file – output the first 10 lines of file
  • tail file – output the last 10 lines of file
  • tail -f file – output the contents of file as it grows, starting with the last 10 lines

show hidden files with -a , show details with -l

Determine file type, i.e. check if somthing is a symbolic link.

Counting Files in the Current Directory

This uses wc to do a count of the number of lines (-l) in the output of ls -1. http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x700.html

  • chmod octal file – change the permissions of file to octal, which can be found separately for user, group, and world by adding:
  • 4 – read (r)
  • 2 – write (w)
  • 1 – execute (x)
  • chmod 777 – read, write, execute for all
  • chmod 755 – rwx for owner, rx for group and world
  • tar cf file.tar files – create a tar named file.tar containing files
  • tar xf file.tar – extract the files from file.tar
  • tar czf file.tar.gz files – create a tar with Gzip compression
  • tar xzf file.tar.gz – extract a tar using Gzip
  • tar cjf file.tar.bz2 – create a tar with Bzip2 compression
  • tar xjf file.tar.bz2 – extract a tar using Bzip2
  • gzip file – compresses file and renames it to file.gz
  • gzip -d file.gz – decompresses file.gz back to file
  • top – display all running processes
  • kill pid – kill process id pid
  • killall proc – kill all processes named proc *
  • bg – lists stopped or background jobs; resume a stopped job in the background
  • fg – brings the most recent job to foreground
  • fg n – brings job n to the foreground

Display your currently active processes

Show full command including arguments.

  • ping host – ping host and output results
  • whois domain – get whois information for domain
  • dig domain – get DNS information for domain
  • dig -x host – reverse lookup host
  • wget file – download file
  • wget -c file – continue a stopped download

Ubuntu apt update apt upgrade apt install pkg

Node.js, Javascript package manager

grep "denied" /var/log/audit/audit.log 

Graph with gnuplot interactively:

apt update apt install gnuplot-x11 gnuplot 
# SET TERMINAL set term gif set output 'frequency.gif' # set title "Word Frequency" # Axes label # set xlabel "Words" # set ylabel "Frequency" set xtics rotate by -90 plot "frequency.dat" using 1:xticlabels(2) with boxes

Create symbolic link link to file

Without -s , then create hard link.

Источник

CentOS command Cheat Sheet

In this blog, we will go through a comprehensive list of CentOS commands that everyone should know when using the system.

CentOS command Cheat Sheet

List of content you will read in this article:

If you're new to CentOS, mastering the commands and tools will go a long way toward enhancing your productivity. The blog is a compilation of nearly every important CentOS command that you need to work smoothly. But before jumping on that, let's brush up with the basics.

A Quick Overview of CentOS

Community Enterprise Operating System or CentOS is a free and open-source commercial operating system compatible with Red Hat Enterprise Linux (RHEL). Gregory Kurtzer founded centOS, and CentOS developers use the RHEL source code to create a product that is quite similar to RHEL.

CentOS is a development platform that is one of the best and most influential Linux distributions available. It's a community-driven free software project that aims to create a stable foundation for open source communities. It's versatile, as well as safe and durable. It also includes multiple corporate-level security updates, making it a fantastic solution for any application. Have a look at the benefits of using CentOS:

  • It virtualises using a Kernel -based Virtual Machine and gives maximum availability and performance.
  • CentOS has a committed developer community that keeps it up to date and guarantees compatibility with both new and old applications.
  • CentOS releases are revised on average every six months, and each release has a ten-year support period.
  • Red Hat's security team is adept at detecting threats and maintaining a high level of security. The Security-Enhanced Linux kernel addition is also included with CentOS.

CentOS Commands Cheatsheet

Help Commands

It is used to find concise descriptions of system commands by searching the Whatis database for entire words.

Displays full path to shell commands

Search and discover command's binary, source, and man pages

Look for help and man pages containing specific phrases and instructions by searching a database of short descriptions.

Lists Manual pages for the respective command

File Operations

Concatenate files or print a file on the monitor.

Make a new file and modify the timestamps.

Copy files or directories.

Moves files or directories.

Removes directories or files in a recursive manner

It is used for creating a symbolic or hard link for a file.

Viewing a single file on a single page, along with the ability to go backwards.

Printing the first ten lines of a file.

Printing the last ten lines of a file.

Counts the total number of words or characters there are in a file.

Shows the status of a file or a file system.

Remove parts of input lines.

Combine multiple lines of text in a single file.

Process Management

Provide an update on existing procedures.

Displays a tree of processes.

Demonstrate real-time procedures.

PID is used to terminate a process.

Stop a process permanently via name

Looking up for processes or signals based on the same and other attributes.

Look for information on the process.

Stop the task instead of keeping it on halt permanently.

The addition of this after a command puts the process in the background.

Displays all the jobs running in process

Partitions and Disk Management

Report on the amount of disc space used by the file system.

Mount a file system or see what's mounted.

Identifies processes via files or sockets.

Displays a list of the system's open files

Accounts and Security Admini­str­ation

Used for creating new groups

Manipulating the description of a particular group

Modifying a user’s account

Updating a user’s password

Editing the password or shadow password of a group

Editing groups or shadow groups

Modifying password policies

Networking

Set up the network interface.

Shows and manipulates IP routing table

Replaces ifconfig, arp, and route by displaying and manipulating routing, devices, policies, and tunnels.

It brings up the network interfaces

It brings the network interfaces down

Sends ICMP ECHO_R­EQUEST to network hosts

Directory Operations

Removes all the contents from your screen

Displays running directory on the screen

Lists down all the content of a directory

Some Frequently-used CentOS Commands

top

This command provides a list of processes or threads that the system kernel is currently using. This is important for determining if something is clogging up your system's resources. The first section you'll notice is a summary, followed by the fields and columns heading, and finally, the task area. You'd use this to see if a process is hung or using up all of your system's resources before keeping it on halt.

Nmap

Nmap allows you to swiftly scan networks for open ports, application version information, and a variety of other important and sensitive data. You can close any gaps in your security plan by listing information such as what ports are open. Nmap is a powerful tool, and reading the man pages is a must to comprehend all of the choices and capabilities available fully.

rpm -ql or dpkg -L

These two commands are used to quickly locate all of the files connected with a specific package. It will display all of the files as well as the package name's location. Rpm is for RHEL/CentOS systems, while dpkg is for Debian systems.

sosreport

Sosreport is one of the scripts that our customers regularly use during break/fix issues. It creates a backup of the system's configuration and diagnostic data, which can be utilised for further debugging and troubleshooting. It's compatible with xsos, a software that reads the reports created by sosreport.

lsmod

This command organises and arranges the output of modules in /proc/modules as well as any presently loaded kernel modules.

Final Thoughts

Finally, CentOS comes with a plethora of other tools and utilities, and the ones mentioned earlier cover pretty much all the crucial and frequently-used ones.

Источник

Читайте также:  Настройка linux через proxy
Оцените статью
Adblock
detector