Ubuntu Command Line for Windows Users

Print this articlePrint this article
Ubuntu Command Line for Windows Users

One of the biggest confusion for a former Microsoft Windows user would be use of command line, or shell utilities. How to list directory in Linux? How to copy file? How to clear screen? Those are amongst the top questions here.

In this article, we will try to give you narrow list of most used cross-system commands, so that you won’t be lost next time you open your terminal window.

Terminal window

To open command line, or shell, in Ubuntu go to Applications > Accessories > Terminal.

Ubuntu Shell: Open Terminal

Ubuntu Shell: Open Terminal

In open terminal window, you will see command line prompt.

It is formatted as username @ hostname:(directory name)$ instead of C:\> which you could observe in Microsoft Windows.

Please, note that unlike Microsoft Windows, Ubuntu and all other Linux distributives (or distros) use slash (‘/’) in for directory paths, and NOT backslash (‘\’).

Generally all commands are executed with ‘-‘ switch (eg. ‘ls -l’) instead of ‘/’ (eg. ‘dir /b’) switch.

In addition, to get help on desired command, you should append-- help’ instead of ‘/?’ as you would do in Microsoft Windows.

Directory structure

  • / - root folder (think of it as C:\)
  • /bin – basic utilities
  • /boot – contains Linux kernel files and grub boot loader
  • /cdrom – lists CD-ROM content, if one is attached and disc is present (and NOT empty)
  • /dev – contains descriptors (handlers) of devices, accessible as normal files (eg. /dev/hda1 or /dev/sda1 can be your hard drive’s descriptor)
  • /etc – contains miscellaneous configuration files (eg. /etc/init.d contains boot up scripts)
  • /home – contains users’ home folders
  • /lib – contains system libraries (think of them as you would of files in Windows\System32 folder)
  • /lost+found – contains lost files, restored by check disk utility
  • /media – contains removal media folders (such as floppy disk or flash card)
  • /mnt – contains all mounted file system folders (eg. CD-ROM, mounted image or network drive)
  • /opt – contains settings for some applications
  • /proc – contains virtual files, representing variety of system-related information (eg. /proc/version contains version of currently running Linux kernel)
  • /root – administrator files folder
  • /sbin – has common system applications
  • /sys – also contains virtual files related to various system resources
  • /tmp – contains temporary files (like C:\Windows\Temp)
  • /usr – contains most of installed software, function libraries and help files
  • /var – contains different current information (such as log files, mail data and printer spooler)

Folder navigation

To change directory, you may use the same ‘cd’ command as in Microsoft Windows, except you should type the path with slashes. For example:

  • cd / – change folder to / (root folder; like C:\)
  • cd /home – change folder to /home (like C:\Users)
  • cd /var/log – change folder to /var/log (like C:\Windows\Logs)

NOTE: You may NOT use ‘chdir’ command, as it will NOT work.
To list directory content use ‘ls’ command instead of ‘dir’:

  • ls . – list current directory content in short format (equivalent to dir /b)
  • ls -la /usr/bin – list /usr/bin in long format (pretty much like dir command’s defaults)

To create a directory, you may use ‘mkdir’, but you can’t use ‘md’:

  • mkdir newfolder – creates new folder called ‘newfolder’
  • mkdir one two – creates 2 new folders named ‘one’ and ‘two’
  • mkdir “Good folder” – creates one folder named ‘Good folder’

To remove a a directory, you may use ‘rm’ instead of ‘rd’:

  • rm one two – removes 2 directories named ‘one’ and ‘two’
  • rm -f “Good folder” – removes directory named ‘Good folder’ and files inside it
  • rm –rf newfolder – removes directory ‘newfolder’, all subdirectories and files

To move a directory, you should use ‘mv’ instead of ‘move:

  • mv somedir /home – moves ‘somedir’ directory to /home

File attributes

There is quite significant difference between file attributes on Linux system, and hence Ubuntu, and file attributes on Windows system. Main difference is that on Linux attributes are playing access control role, while on Windows they are mostly additives.

So, if on Windows we have 4 attributes:

  • R Read-only file – writing is disabled (like on CD-Rom)
  • A Archived file – file is archived by system
  • S System file – file belongs to system core
  • H Hidden file – file is invisible with directory listing commands
  • I Non-indexed – file with non content indexing (modern Windows)

Plus date and time of modification, on Linux we have:

  • d – file is actually a directory or l – file represents symbolic link to another file or directory
  • r – file can be read
  • w – file can be written
  • x – file can be executed (and searched)

Now those last 3 attributes ‘rwx’ – Read, Write and Execute – are present for 3 roles: user himself, group user is belonging to and others.

So, when you list files with ‘ls -la’ command, you see something like this:

-rwxr-xr-- 1 root 1153 2011-04-06 00:43 .bash_profile

You should understand it like that:

  • - – this file is not a directory nor symbolic link
  • rwx – this file can be read, written, searched and executed by user who created it
  • r-x – this file can also be read, searched executed by users from the same group as user who created it, but it cannot be written by them
  • r-- - this file can only be read by users not belonging to the same group as user who created it
  • 1 – number of files (in case with directories, it will be 1+number of files in directory)
  • root – owner user’s name
  • 1153 – file size (in case with directories, size of file record, needed to store all information about directory)

Now to change these attributes, you should use ‘chmod’ command, instead of ‘attrib’, as follows:

chmod [role: uga][+/-/=][mode: rwx]

Where:

  • u – user role permissions
  • g – group role permissions
  • a – everyone’s permissions

So, user’s group to write to file, one can issue command like this:

chmod g+w .bash_profile – adds writing permission to file for file owner’s group users

And to remove read permissions from everyone, but user and his group, one could issue command like that:

chmod a-r .bash_profile – removes reading permission from all who is not user nor in his group

File management

To copy file in Ubuntu, one should issue ‘cp’ command instead of ‘copy’ as he would do in Windows:

cp .bash_profile /var/tmp – copies .bash_profile to directory at /var/tmp

To remove file in Ubuntu, one should use ‘rm’ command instead of ‘del’ as he would do in Windows:

rm /var/tmp/.bash_profile – removes .bash_profile file at /var/tmp

To view contents of file, you should use ‘cat’ command instead of ‘type’:

cat /usr/share/common-licenses/GPL – will display GPL file from /usr/share/common-licenses folder folder (identical to ‘type c:\windows\system32\license.rtf’)

To compare two files, you should use ‘cmp’ command instead of ‘fc’, and append ‘-l’ option, if you want it to display all differences:

cmp -l /usr/share/common-licenses/GPL-2 /usr/share/common-licenses/GPL-3 – will display byte-by-byte comparison of two files, which in this case are GPL license files version 2 and 3. Output is produced as follows:

[file offset at which the difference was found] [byte from file #1] [byte from file #2]

17987 12 40 – tells us that at offset 17987, in file one we have byte with ASCII decimal value of 12, while in file two – with ASCII decimal value of 40.

To edit file’s content, you should use ‘nano’ command instead of ‘edit’:

nano .bash_profile – opens .bash_profile in nano editor (like ‘edit .bash_profile’)

File system management

To attach disk to your system (like mounting removable media, network drive or disk images), you must issue command:

mount -t [file system type] [descriptor] [directory-to-mount-to]

Where file system type is one of:

  • autofs – automatically detect file system
  • cifs – CIFS (Samba-like) network protocol (for mounting remote drives)
  • ext/ext2/ext3/ext4 – default Linux file system (for HDD most likely ext4 or ext3; for other devices could be ext/ext2)
  • iso9660 – default CDROM file system type
  • msdos – default FAT file system type
  • nfs – classical (for Linux) NFS network protocol
  • nfs4 – modern (less compatible, but more advanced) NFSv4 network protocol
  • ntfs – Microsoft Windows compatible NTFS file system
  • smbfs – Samba File System
  • udf – extended CDROM file system (the one that allows long file names)
  • usbfs – default file system for USB drives (unless its formatted with other file system type)
  • vfat – Windows-compatible VFAT file system.

So, if you want, for example, to mount CD-Rom manually, you should issue command like:

mount -t udf /dev/cdrom /mnt/cdrom – this will attach loaded disk’s file system to /mnt/cdrom directory.

NOTE: /mnt/cdrom is not created by default, so if you do mount it, create it first (‘mkdir /mnt/cdrom’)

To detach disk from your system, issue command:

umount [path-to-mounted directory OR path to device descriptor]

For example:
umount /dev/cdrom – detaches CDRom file system and releases lock from eject button.

NOTE: In case it fails to detach, you can add ‘-f’ switch to enforce un-mounting (‘umount -f /dev/cdrom’).

To display list of currently active mounts, issue ‘mount’ command with no options.

Disk management

To display partition table, Linux have ‘fdisk’ utility (as in older Windows versions), issue command:

sudo fdisk -l [device descriptor, such as] /dev/sda – will list partition table for /dev/sda

If disk doesn’t have partition table, you will see only disk information and message similar to ‘Disk /dev/sda1 doesn’t contain a valid partition table’.

NOTE: We appended ‘sudo’ command in front of ‘fdisk’, which enables us to perform administrative actions. See next section for detailed explanation.

  • To alter partition table, launch fdisk with no parameters. You’ll find yourself in an interactive prompt, switched by ‘ENTER’ key.
  • To get help: type ‘m’ and press ‘ENTER
  • To get list of supported partition types: type ‘l’ and press ‘ENTER
  • To print partition table: type ‘p’ and press ‘ENTER
  • To verify partition table: type ‘v’ and press ‘ENTER
  • To add new partition: type ‘a’ and press ‘ENTER’. You will be asked to define partition number.
  • To remove partition: type ‘m’ and press ‘ENTER’. You will be prompted for a partition number.
  • To make partition bootable: type ‘a’ and press ‘ENTER’. You’ll be prompted for a partition number.
  • To create DOS-compatible partition table: type ‘o’ and press ‘ENTER
  • To quit and commit changes: type ‘w’ and press ‘ENTER
  • To exit and omit changes: type ‘q’ and press ‘ENTER
  • To format file system, use ‘mkfs’ command instead of ‘format’:

mkfs -t [file system type] [descriptor]

Where file system type is one of:

  • ext2 – Linux EXT2 file system type (mostly used for removable media, nowdays)
  • ext3 – Linux EXT3 file system type (general use for most Linux distros)
  • ext4 – Modern Linux EXT4 file system type
  • msdos – MS-DOS-compatible FAT file system
  • ntfs – NTFS-compatible file system
  • vfat – Windows-compatible VFAT file system

For example:

mkfs -t ext4 /dev/sdb1 – will format device at /dev/sdb1 with EXT4 file system.

Administrator control

If you need to perform any changes that affect the system as whole, you will need to activate administrator mode. This can be done in two ways:

  1. Append ‘sudo ‘ in front of every command that requires escalated privileges (such as fdisk). You will then be asked for system administrator’s password, which defaults to yours normally.
  2. Type in ‘sudo su’ to activate administrator console. This will also ask you for your administrative password, so be ready to input it.

NOTE: Second way is strongly discouraged amongst Linux community, as considered to create potential security breach. While it is true that work in ‘god mode’ is NOT ideally secure, it is true as well, that sometimes you may just need it.

This concludes our – Ubuntu Command Line for Windows Users – article. We hope you enjoyed reading it as much as we enjoyed bringing it to you.

Stay tuned for more interesting articles, and please, leave your comments below, so that we could improve material we bringing to you.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <span>
  • Lines and paragraphs break automatically.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.
Image CAPTCHA
Enter the characters shown in the image.