0% found this document useful (0 votes)
29 views5 pages

Linux System Commands

This document provides a comprehensive guide to various Linux system commands, including commands for checking distribution information, managing files and directories, and handling permissions. It also covers searching for files, viewing command history, and managing system resources like memory, disk, and CPU usage. Each command is presented with its syntax and purpose, making it a useful reference for Linux users.

Uploaded by

Nel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

Linux System Commands

This document provides a comprehensive guide to various Linux system commands, including commands for checking distribution information, managing files and directories, and handling permissions. It also covers searching for files, viewing command history, and managing system resources like memory, disk, and CPU usage. Each command is presented with its syntax and purpose, making it a useful reference for Linux users.

Uploaded by

Nel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Linux System Commands

Distribution Information
shell
# Debian/Ubuntu

uname -a

lsb_release -a

# CentOS/RedHat

cat /etc/centos-release

cat /etc/redhat-release

# This will provide a lot more information

cat /etc/os-release

Shut down or Reboot


shell
shutdown -h now

reboot

Permissions
shell
# change the user:group ownership of a file/dir

chown root:git <file_or_dir>

# make a file executable


chmod u+x <file>

Files and directories


shell
# create a new directory and all subdirectories

mkdir -p dir/dir2/dir3

# Send a command's output to file.txt, no STDOUT

ls > file.txt

# Send a command's output to file.txt AND see it in STDOUT

ls | tee /tmp/file.txt

# Search and Replace within a file

sed -i 's/original-text/new-text/g' <filename>

See all set environment variables


shell
env

Searching
Filenames
shell
# search for a file in a filesystem

find . -name 'filename.rb' -print


# locate a file

locate <filename>

# see command history

history

# search CLI history

<Control>-R

File contents
shell
# -B/A = show 2 lines before/after search_term

grep -B 2 -A 2 search_term <filename>

# -<number> shows both before and after

grep -2 search_term <filename>

# Search on all files in directory (recursively)

grep -r search_term <directory>

# Grep namespace/project/name of a GitLab repository

grep 'fullpath' /var/opt/gitlab/git-data/repositories/@hashed/<repo


hash>/.git/config

# search through *.gz files is the same except with zgrep


zgrep search_term <filename>

# Fast grep printing lines containing a string pattern

fgrep -R string_pattern <filename or directory>

CLI
shell
# View command history

history

# Run last command that started with 'his' (3 letters min)

!his

# Search through command history

<Control>-R

# Execute last command with sudo

sudo !!

Managing resources
Memory, Disk, & CPU usage
shell
# disk space info. The '-h' gives the data in human-readable values

df -h
# size of each file/dir and its contents in the current dir

du -hd 1

# or alternative

du -h --max-depth=1

# find files greater than certain size(k, M, G) and list them in order

# get rid of the + for exact, - for less than

find / -type f -size +100M -print0 | xargs -0 du -hs | sort -h

# Find free memory on a system

free -m

# Find what processes are using memory/CPU and organize by it

# Load average is 1/CPU for 1, 5, and 15 minutes

top -o %MEM

top -o %CPU

You might also like