- How to change directory in Linux terminal
- How to change directory in Linux terminal
- How to use the Linux command line to change directory or folder
- How to print the current working directory in Linux
- cd command in Linux termianl
- Absolute vs Relative pathname
- Understanding . and .. directories
- How can I return directly to my home directory when using the Linux terminal?
- How do I change directories in the Linux terminal and return to the previous directory?
- A note about symbolic links and cd command
- Linux cd command cheat sheet
- Conclusion
- Is This The Right Way To Change Drives Using Terminal?
- 1 Answer 1
- How do I rename a USB drive?
- 5 Answers 5
- How to change permission of a drive in an external hard disk?
- 3 Answers 3
- 1. Ok technique for files ON an external drive, but the correct technique for files you just copied onto your computer FROM an external drive
- 2. Sometimes better for files ON an external drive
- 3. Better still #1 (or best, if you DO need write permissions for everyone) for files ON an external drive
- 4. Better still #2 (or best, if you do NOT need write permissions for everyone, ie: if read is enough) for files ON an external drive
- What is the equivalent for switching drives in terminal on Linux?
- 7 Answers 7
How to change directory in Linux terminal
M y Dell Laptop came preinstalled with Ubuntu Linux, and I am a new Linux desktop user. How do I change directories in the Linux terminal?
Introduction – On Linux the cd command allows you to change directories when using the terminal application. This page shows how to change directory in Linux terminal using the cd command.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux terminal |
Est. reading time | 3 minutes |
How to change directory in Linux terminal
- To return to the home directory immediately, use cd
OR cd
Let us see all examples and usage for terminal in details.
How to use the Linux command line to change directory or folder
The directory in which the user is currently working is called the current working directory (CDW).
How to print the current working directory in Linux
To display the name of the current/working directory, type the following pwd command:
pwd
cd command in Linux termianl
The syntax is:
cd
cd ..
cd /path/to/dir
When cd command used without stipulating any directory name, cd command returns to the home directory. Let us change the directory to /usr/sbin/, run:
cd /usr/sbin/
Verify it:
pwd
Want to list the files in the /usb/sbin/ directory? Try the ls command:
ls
ls -l
Let us go back to user’s home directory, run:
cd
Again verify it:
pwd
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Absolute vs Relative pathname
The cd command changes the current directory when a directory name provided by the user. The name can be written as an absolute pathname (e.g. cd /etc/httpd/ ) or as local pathname relative to the root directory (e.g. cd conf.d/ ). For example:
cd /etc/httpd/
pwd
ls
cd conf.d/
pwd
ls
The absolute vs. relative pathname for cd command in Linux
Understanding . and .. directories
On Linux the current directory is represented by a single dot ( . ) and two consecutive dots represent its parent directory ( .. ). Thus, to change to the parent of the current directory, run cd . .. For example:
ls
pwd
cd ..
pwd
ls
How can I return directly to my home directory when using the Linux terminal?
How do I change directories in the Linux terminal and return to the previous directory?
Simply pass the — option to the cd:
cd —
Verify it:
pwd
A note about symbolic links and cd command
The -P option instructs cd to use the physical directory structure instead of following symbolic links:
cd -P LinkDir
pwd
The -L option forces cd to follow symbolic links:
cd -L LinkDir
pwd
Linux cd command cheat sheet
Command | Description |
---|---|
cd | Returns you to your login directory |
cd |
tom
Conclusion
The cd command is used to change the current directory in both Linux and other Unix-like systems. See Cd command wiki page.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
Is This The Right Way To Change Drives Using Terminal?
Well I am a newbie in Linux world. Everyday learning by working. I use dual booting and in one drive Windows 7 is installed and in another drive Ubuntu 14.04 LTS is installed. My first O/S was windows 7. There was few drives like Workshop, Movies, Soft etc. Now I was about to change drives in terminal to access files stored in different drives. After spending couple of hours I discovered a way to access different files in different drives. What I did is first of all I mounted lets say /dev/sda2 drive in /media/username folder using this command.
Once mounted then I can easily change directories by using cd command.
Now my questions are.
- Is this really a correct way to change drives to access files?
- I can go forward like $cd /media/username but how to go backward? I mean go back to root or go back to media? In windows CMD I am using cd.. to go one folder back. Is there any similar command for terminal?
- What is the difference between drive and partition?
- How to unmount a drive or any file?
- My last question is as far as I know in Linux files are arranged under root / directory. If so then it might don’t respect windows drive systems. If so then all files should be accessed without mounting any drive to /media/username folder?
1 Answer 1
First, note there is a typo in mount your command. It should be:
Here /dev/sda2 is the device (in this case, a hard drive’s partition) you want to access, and /media/username is your mountpoint, i.e., the location in the filesystem where you want to mount the device.
To answer your questions:
Yes, using cd is the normal way to change directories. And mount is perfectly fine to mount devices that are not already mounted. If you mount it often, you may want to make an entry in /etc/fstab so that in the future you can mount a particular device to a particular mountpoint with self-defined options, e.g., by simply writing mount /media/username . You may even want to consider mounting it automatically, at boot time. There is a lot of excellent documentation on the subject. Just search for fstab .
I guess you want to do a bit of reading about the Linux filesystem. There’s also good documentation for this, see, e.g., here for a short overview. / is the root folder in which everything is contained, organized in various subfolders. Here’s a few hints concerning cd :
- cd (without arguments) will get you to your home folder, typically /home/username
- cd — will get you to the previous folder (where you were before you changed to the current folder)
- cd .. will get you to the parent folder (one level up). This is equivalent to cd.. in Windows CMD.
- cd / will get you to the root folder, though I personally rarely need that.
A (hard) drive is actually a disk that you can store data on. It is usually divided into several partitions. Perhaps confusingly, in the Windows world these partitions are also called drives. This is not the case in the Linux world, though. We simply call them partitions, or perhaps «devices» in a technical context.
To unmount a mounted device, use the command sudo umount , e.g., in your example,
. where /media/username is a mounted partition (you could also use sudo umount /dev/sda2 , though this is perhaps less intuitive). Simply write mount (without arguments) to see a list of all currently mounted devices with their mountpoints.
In Linux, you have to mount each of your Windows «drives» on a separate mountpoint. You are completely free to choose where, and you already know how to do it, as you showed with your mount command. 🙂
Источник
How do I rename a USB drive?
How exactly would I rename a USB drive?
I’ve read that you can go into the Disk Utility, click on Edit Partition, and there is an option to rename the label but I can’t click in the area to rename.
Is there any other way?
5 Answers 5
- Open «Disks» application
- Select the flash drive in the panel on the left
- Press the Unmount button (should look like a «stop button»)
- Click on the gears icon («More actions») and choose «Edit filesystem»
First, obtain the location of your USB drive:
Assuming that your device location is /dev/sdb1/ :
You can safely check the current label without any side effects by issuing the following command:
Most USB sticks are formatted using FAT16/FAT32. To change the label via the prompt, use the mlabel command. The label of a FAT filesystem requires to be exactely 11 characters. No more, no less. When characters are omitted, spaces are added at the beginning, and seemingly random characters are appended at the end.
Install the mtools package (GNU Tools for MSDOS filesystems):
Then you might need to configure the mtools drives settings, hence add the following two lines to /etc/mtools.conf (you will need sudo to edit)
Having saved, you should then be able to look at your USB drive in (say) /dev/sdb1 as drive u:
(See comments . ) Then relabel:
For other filesystems (rarely used for USB sticks), see this page.
Источник
How to change permission of a drive in an external hard disk?
I had an old laptop. When it got complaint I removed its hard drive and started using it as external hard disk. It has an 80 GB of memory allocation for the windows C drive partition. But now i don’t need that partition anymore. But the problem is I am not able to access that drive to paste files into it. How can I make read and write permission to this drive using terminal?
3 Answers 3
If you want to gain ownership of a drive you can use the chown command:
This gives the user ownership over the drive without allowing permission to unauthorized users and -R makes this command recursive so that ownership also applies to all of the existing individual files on the drive as well and not just the drive itself.
You can also use -R to make chmod recursive as well.
1. Ok technique for files ON an external drive, but the correct technique for files you just copied onto your computer FROM an external drive
This works: recursively ( -R ) change the username (the part before the colon : ) and groupname (the part after the colon : ) to your username:
BUT, the problem with this is that it makes the external disk difficult to share between multiple usernames and/or on multiple computers, because each person on each system who needs access to these files must either have the same username , or must be part of the same groupname . Having the same username only works if it is the same person, so that doesn’t always make sense. Having the same groupname is okay if it is consistently the same people using the drive, and they all add themselves to the same group with:
BUT, if the groupname doesn’t exist on one system, and just shows up as a number, such as 5000 , when you look at it with ll ( ls -alF ), then you can’t easily add yourself to the same group because usermod -a -G 5000 produces this error:
2. Sometimes better for files ON an external drive
So, that leads us to this solution: just give full permissions to these files to everyone:
BUT, that also marks ALL files as executable, which doesn’t really make sense. You don’t want to arbitrarily mark every single file as executable, as that can pose a security risk, and also be annoying when every time you double-click a text file to open and edit it, it asks you if you’d like to run/execute it.
3. Better still #1 (or best, if you DO need write permissions for everyone) for files ON an external drive
So, that leads me to my recommendation: give full permissions to everyone ( -a , or ‘a’ll), but only set the executable bit (ie: use +X , NOT +x ) if it is either a directory, OR already set for one or more of «user», «group», or «other», like this:
man chmod says about the capital X versus lower-case x option:
. execute/search only if the file is a directory or already has execute permission for some user (X).
4. Better still #2 (or best, if you do NOT need write permissions for everyone, ie: if read is enough) for files ON an external drive
BUT, even better still, if you can get away with it: if you don’t really need guaranteed write permissions for everyone, just ensure you have at least read permissions for everyone on the drive, like this:
Then, apply permissions -R a+rwX only AFTER copying the files to your local machine from the external drive:
Источник
What is the equivalent for switching drives in terminal on Linux?
In DOS, I switch between different drives by typing c: , d: , e: and so forth. But it doesn’t work that way in Linux.
Could anyone please tell me how to switch between different drives?
7 Answers 7
Linux doesn’t really have a way to work with «drives», per se, except with system utilities that access partitions; they often need to specify the drive that contains the partition. But if your drives each only have one partition, it doesn’t really matter.
Anyway, to access a drive, you actually need to specify the partition in some way, usually by a definition like /dev/sda1 (1st partition on 1st drive) or /dev/sda2 (2nd partition on first drive). Using the Disk Utility or gparted, you can see all the partitions graphically. If you’re only using the terminal, I’ve found that the command «blkid» is handy to list the drives with their UUIDs. I use the form:
Using the terminal, you need to mount a partition to actually use it. This is actually pretty easy to do. In most cases, you would want to use an empty directory as the «mount point»; if the directory is not empty, its contents will be masked and unavailable during the mount. This may be useful in certain circumstances, such as testing or temporarily changing a configuration for some other reason, as it will alleviate the need to rename or delete the current contents.
If you have a directory named /mnt/drive2 (/mnt is commonly used, but it can be in your home directory if you want), and your drive is /dev/sdb, with a single partition, then the simplest command is:
where «type» is the type shown in the blkid command, such as ntfs, ext4, etc.
EDIT: to experiment, don’t be afraid to try the mount command. It is only temporary until you reboot (or unmount using the «umount» command). To make it permanent, you need to enter it into /etc/fstab . If you want to do that, you can experiment by creating an entry, then using the command «mount -a» to mount everything in /etc/fstab . If there are errors, it will tell you, and you can correct and repeat until it works.
Источник