Skip to content

Instantly share code, notes, and snippets.

@cas4ey
Last active March 6, 2018 11:16
Show Gist options
  • Save cas4ey/e6ee0be454f6bcdc7aff7473564fa960 to your computer and use it in GitHub Desktop.
Save cas4ey/e6ee0be454f6bcdc7aff7473564fa960 to your computer and use it in GitHub Desktop.
Linux
# This Gist contains several files
# with linux commands hints/cheatsheet
#
# Click 'View linux.hints.0.sh' to view
# all files in this Gist.
#
#!/bin/sh
#######################################
# Move or rename files and directories
mv # Если говорит "каталог не пуст", значит уже есть файл или папка с таким именем
#######################################
# Copy files/dirs
cp file destination # Copy file to destination
cp -R dir destination # Copy directory to destination
#######################################
# Create soft link
ln -s source_file destination_file # Create soft link to 'source_file' with path/name 'destination_file'
ln -s ../test/run_test.sh ./run_test.sh # Example
#######################################
# Remove files/dirs
rm file # Will remove file which is not write-protected (!!!)
rm -r dir # Will recursively remove dir and it's contents (which are not write-protected)
rm -f file # Will force remove file (even write-protected)
rm -rf fdir # Will force remove file/dir and it's contents completely EXCEPT hidden files (starting with '.')
rm -rf * # Will force remove all files/dirs in CURRENT directory EXCEPT hidden files (starting with '.')
#######################################
# Change file permissions
chmod permissions file # Will set permissions to file
chmod +x file # Will ADD execution permission to file by all users
chmod -x file # Will REMOVE execution permission to file by all users
chmod 777 file # Will set read-write-execute permissions to file by all users
r = read, w = write, x = execute, d = directory
#######################################
# Change owner
chown user:group file # Will change owner of the file to user 'user' from group 'group'
chown -R user:group * # Will change owner for all files/dirs recursively
#!/bin/sh
#######################################
# Show contents of current directory
ls -F # Will add '/' to directories
ls -l # Will show files permissions
ls -1 # Will use single column in output
ls -a # Will show all contents including hidden files (which name starts with '.')
ls -al # Show all files and it's permissions
#######################################
# Show current directory full path
pwd
#!/bin/sh
#######################################
# Find process
ps -aux # See launched processes
ps -aux | grep process_name # Search for launched process with specified name
#######################################
# Kill process
kill -9 pid # Kill process with id == pid
kill -s SIGSEGV pid # Send SIGSEGV signal to process with id == pid
#!/bin/sh
#######################################
# Find files by name
find dir -name "pattern" # Case sensitive search for all files in dir and it's subdirs matching specified pattern
find dir -iname "pattern" # Case insensitive search
find . -iname "*.log" # Find all .log files in current directory and it's subdirectories
find -iname "*.log" # Same as 'find . -iname'
#######################################
# Find text in files
grep "pattern" file # Case sensitive search of text matching given pattern (can find part of a word)
grep -i "pattern" file # Case insensitive search
grep -R "pattern" * # Case sensitive RECURSIVE search in all files in current directory and it's subdirectories
grep -Ri ....... # Case insensitive recursive search
grep -l # Display only file names which text mathes given pattern
#######################################
# Redirect application output to file
app > app.log # Redirect app stdout to app.log
app 2> app.log # Redirect app stderr to app.log
app > app.log 2>&1 # Redirect stdout and stderr to app.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment