https://github.com/r0f1/linuxhelp Skip to content Sign up * Why GitHub? + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} r0f1 / linuxhelp Public * Notifications * Fork 10 * Star 101 * Helpful linux commands. 101 stars 10 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 1 branch 0 tags Code Latest commit @r0f1 r0f1 Update README.md ... 4b69dc9 Jul 5, 2021 Update README.md 4b69dc9 Git stats * 37 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time README.md Update README.md Jul 5, 2021 View code [ ] Linux commands Help Basics More Basics Multiple Commands Search Screen Misc Cursor Tricks Creating an SSH key Permissions Snippets and Useful .bashrc Additions Resources README.md Linux commands Help Command Example Comment man man cd Manual man ls Get help (close with q). cd Also help. --help --help Tab (1x Auto completion. or 2x) | See previous command. Ctrl+C Kill the current process or command (e.g. if something hangs). Ctrl+D Logout. Closes the console if you're not in an ssh session. Similar to exit. Search through your history. Start typing and it will auto-complete. Hit Ctrl+r again and it will Ctrl+R cycle though the other auto-completion options. Hit Enter and the command will execute. Hit -,- to edit commands. Basics Command Example Comment Super user do sudo Run a command with elevated privleges. sudo ls Will ask you for a password. Only possible, if you were granted administrative rights on the system. Change directory cd test . (dot) is the current directory cd .. .. (dotdot) is the upper/partent cd cd - directory cd ~ / (slash) is the root directory cd /path/to/my/ ~ (tilde) is your home directory folder - (minus) switches to the previous directory ls ls -la ls ls -l -a (same as ls above) List contents of a folder ls -halt (more -h human readable ls arguments) -a all ls -d */ (list all -l more information ls directories) -t order by time ls test (contents of subfolder) ls *.txt (show only .txt files) mkdir Make directory mkdir test Creates a new immediate subfolder with mkdir -p the given name. -p Create path. pwd Print working directory Shows the current path. mv mv text.txt test Move a file mv test.txt Can also be used for renaming (second bla.txt example) cp cp text.txt test Copy a file cp -p text.txt -p preserves mode, ownership, and test timestamps Can also rename. rm text.txt Remove rm rm -rf test Warning: Cannot be undone! rm -rf rm *.tmp (removes -f force, no confirmation all files with dialog, no warnings file ending *.tmp) -r recursive, for folders Clear the console. clear Gives you a fresh view. Similar to Ctrl+L reset Reset the console. Like clear but more powerful. More Basics Command Example Comment head head text.txt Display first/last lines of file tail head -n 20 Default n=10. text.txt Display contents of a file of a file, read-only h help q close f,b forward, backward one page less less text.txt e,y forward, backward single line / search n,p next, previous during search -i activate case insentitive search File editor nano nano text.txt Ctrl+x to close Alt+/ to go to the end of a file Change permissions for file chmod chmod 777 test 777 gives the folder all possible rights. Further explanation see below. chown sudo chown alice Change file owner folder du -h Disk usage du du -sh . -s summary du -sh * | sort -h human readable -h Disk free df df -h Show remaining disk space. -h human readable Task manager htop View currently running processes. Q to close. Multiple Commands Command Example Comment Concatenate commands ; Execute after . Double ampersand && Execute after but only if finished successfully. > Redirect ls -a > the output of a command into a file result.txt > creates/overwrites a file >> ls -a >> >> creates/appends to a file result.txt 2> redirects the errors 2> Pipe history | the output of a command to less. | less Especially useful for history command ls | less (displays the latest commands) or folders with many files in them (last example) Search fselect - Search for files in a modern, SQL-like fashion. Command Example Comment grep find Screen Command Comment screen Create a new session. Ctrl+A,D Detach from current screen session. Ctrl+D End current session. Similart to exit. screen -r Reattach to session. screen -ls List all sessions. screen -S Create a new screen session with logging enabled. -L screen -r Reattach to session with if there are multiple ones. screen -rx Attach to session that is already attached. Ctrl+A,Esc Enter scroll mode. Use | and | or Pg Up and Pg Dn to scroll. Hit Esc to exit scroll mode. Misc Command Example Comment passwd passwd alice Change password rsync rsync -aP file.txt Rsync servername:/home/user copy files from/to a server /data Secure copy scp scp files from/to a server username@example.com: -r recursive (include subfolders) /my/folder/*.txt . The example copies all files from the given directory then end in .txt to the local directory (dot) ssh ssh Secure shell username@example.com Connect to a server ssh -t ssh -t -t Close connection immediately " username@example.com after the command is done " "ls -a" Further explanation see below. stat stat text.txt Display file Status, creation date, last modification date, etc. su su root Switch user Touch a file. Creates a new, empty file if the file does touch touch text.txt not already exist. touch makefile Especially helpful to create makefiles under Windows. Actually the command is used for changing file timestamps. watch watch -n60 ls Repeat a command every n seconds. which which nano Display where the command / program is coming from. Cursor Tricks Command Comment Ctrl+A Jump to beginning. Ctrl+E Jump to end. Ctrl+W Delete one word left of the cursor. Ctrl+U Delete entire line. Ctrl+Y Paste back what you just deleted. Creating an SSH key # Creating ssh-keygen -t rsa -b 4096 -N "" -C "" -f keyname mv keyname* ~/.ssh # Setting access rights chmod 700 ~/.ssh && chmod 600 ~/.ssh/* # ~/.ssh/config Host github HostName github.com User git IdentityFile ~/.ssh/keyname # This logs into the server, and copies the public key to it. ssh-copy-id -i ~/.ssh/keyname user@remote_machine # Checking the ssh procesd ssh -T git@github.com eval $(ssh-agent -s) ssh-add ~/.ssh/keyname ssh -T git@github.com Permissions Type chmod xxx to change permissions where xxx is the numerical code from the table below. Explaination of the Codes: . ... ... ... (type) (user persmissions) (group permissions) (world permissions) The first item can be d (a directory), - (a regular file) or l (a symbolic link). The following three triplets specify permissons for the user, group and world in that order. In each tripplet, permissions can be r (read), w (write), x (execute) or - (not assigned). Setting permissions can be done via numbers: r=4, w=2, x=1 and -=0. Setting Code Use Case ---------- 000 Locking even yourself out. Use chmod again, if this happens. -r-------- 400 An auto-generated password file (e.g. ~ /.google_authenticator). -rw------- 600 ~/.history, all the ssh keys in your ~/.ssh folder. -rwx------ 700 Your ~/.ssh folder. -r--r--r-- 444 A textfile, that others should see as well, but nobody should modify it. -r-xr-xr-x 555 A folder, that others should be able to cd into as well, but nobody should modify it. -rwxr-xr-x 755 Files and folders you want other people to see. -rwxrwxrwx 777 Files and folders you want other people to see and modify. The most open permission. Permissions on directory have the following meaning: The read bit allows to list the files within the directory. The write bit allows to create, rename, or delete files within the directory, and modify the directory's attributes. The execute bit allows to enter the directory, and access files and directories inside. To view permissions as numerical code: stat -c %a . What does `s` mean? (click to expand) "s", like "x", means something different for directories and regular files. For files, "x" means "executable" of course. For directories, it means "searchable." Without "x" permission on a directory, you can't set it to be your current directory, or get any of the file information like size, permissions, or inode number, so that you effectively can't access any of the files. If a directory has no "r" permission, you can't get a listing, but if you know a file is there, you can still access the file. Now "s", for files, means "setuid exec." If a file has s permission, then it's executable, and furthermore, the user id and/or group id of the process is set to the user or group id of the owner of the file, depending on whether it's the user or group "s" that's set. This is a way to give limited root powers to a user -- a program that runs as root when an ordinary user executes it. For example, the "passwd" program, which can change otherwise write-protected files on behalf of a user, works this way: it's owned by the "bin" group (generally) and has g+s so that it can write to /etc/passwd and/or /etc/opasswd which are also owned by group "bin." For directories, "s" means "sticky". If a directory has "s", then the owner and/or group of any files put into the directory are set to the owner/group of the directory. This is often used on CVS repositories, so that the files in the repository end up all owned by the same person and/or group, even though they're put in by different people. I use g+s on all the CVS repositories I set up. Snippets and Useful .bashrc Additions # Finding out which linux you are using uname -m && cat /etc/*release # Bulk renaming of files rename 's/ch0/ch/gi' *.tiff # Make output of df and du human readable alias df='df -h' alias du='du -h' # Count files in directory alias fcount='ls -1 | wc -l' # Disable "Save workspace" promt when closing R alias R='R --no-save' Resources * Modern Unix Alternatives * Presentation * Linux Directories Explained in 100 Seconds About Helpful linux commands. Resources Readme Stars 101 stars Watchers 4 watching Forks 10 forks Releases No releases published Packages 0 No packages published * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.