Useful Linux commands: Difference between revisions

From Earlham CS Department
Jump to navigation Jump to search
Ttphan21 (talk | contribs)
mNo edit summary
Tdjones22 (talk | contribs)
Starting fresh; added some file and directory management commands.
Line 1: Line 1:
This page will contain some useful Linux commands.
The one-stop shop for all your Linux command needs. Most commands listed will work on our machines, though that can vary based on installed packages and/or operating systems.


/Linux world directory is a special type of file that contains a list of objects (files or other directories). Folder and directory are interchangeable terms.  
== File and Directory Management ==
Directories are organized in a tree structure. /.  
=== ls ===
Lists all files and directories
* <code>ls -a</code> - List all files, including hidden ones like .ssh, .bashrc, and so on.
* <code>ls -l</code> - Include extra file information like permissions, owner, groups, modified date, and more.
* <code>ls -s</code> - List size of files in blocks.
* <code>ls -S</code> - List by size, largest first.


=== cd ===
Some useful arguments:
Used to change the directory.
* ls -l displays the permissions, user and group ownership, and date of creation in addition to displaying the contents.
* <code>cd</code> - When no path is specified, you will move to the user's home directory. As root, you will move to <code>/root/</code>. As your user, you will move to <code>/eccs/home/<username>/</code>.
* <filename> - if a filename starts with dot, then it is not visible). ls -a shows you hidden files too.
* <code>cd /path/to/file</code> - When changing directories, if you're not in the immediate parent directory, you need to specify the full path. For example, if my current working directory is <code>/etc</code>, I can <code>cd jupyterhub</code> since it's within <code>/etc</code>. However, if my current working directory is <code>/bin</code>, I would have to specify the full path for <code>/etc/jupyterhub</code>.
 
 
cd - no path is provided, then it brings you to the previous working directory.  
you to the parent directory of your current working directory.  
* cd ~  - your home directory
* cd / - here the path is / so it brings you to the root directory.
 
the full path of your current working directory
 
 
cp <source_file_path> <target_file_path> (copy)- make a copy of a file. (use -r option for folders)
 
 
vi/nano/.
 
 
 
 
 
 
 
directory
 
/directory
 
/directory
 
 
to stdout
 
 
the user
 
apt/
 
 
 
/time
 
 
 
mount, df, ps(pstree), awk, sed, head, tail, ln, alias, scp, ssh, wget, find, which, locate, chown, man, tar, ifconfig, ping
 
 
Piping('|')
 
 
Keyboard Shortcuts:
 
Tab - autofill the file or directory name currently being typed
 
Up/down arrows - go through the history of commands you have typed
 
Ctrl + C - end the command that is currently being executed (useful for getting out of a place where it keeps asking you to enter something and you don't want to)
 
Tested and working 2022

Revision as of 00:24, 23 March 2025

The one-stop shop for all your Linux command needs. Most commands listed will work on our machines, though that can vary based on installed packages and/or operating systems.

File and Directory Management

ls

Lists all files and directories

  • ls -a - List all files, including hidden ones like .ssh, .bashrc, and so on.
  • ls -l - Include extra file information like permissions, owner, groups, modified date, and more.
  • ls -s - List size of files in blocks.
  • ls -S - List by size, largest first.

cd

Used to change the directory.

  • cd - When no path is specified, you will move to the user's home directory. As root, you will move to /root/. As your user, you will move to /eccs/home/<username>/.
  • cd /path/to/file - When changing directories, if you're not in the immediate parent directory, you need to specify the full path. For example, if my current working directory is /etc, I can cd jupyterhub since it's within /etc. However, if my current working directory is /bin, I would have to specify the full path for /etc/jupyterhub.