How does one read the contents of a text file located on the desktop using the terminal?
Solution 1
Cat is a UNIX command that lets you read text files. So, you can just run the command cat ~/Desktop/FILENAMEHERE
unless you are root. If you are root, you must type cat /home/*/Desktop/FILENAMEHERE
. Also, you should upgrade to Ubuntu 14.04 or 14.10. This isn't Windows. It's not okay to use an older version of Ubuntu like it is when you use Windows. You should ALWAYS (no matter what circumstances) use the latest stable release of Ubuntu (currently 14.10) or the current LTS release (currently 14.04, what I recommend to you).
Solution 2
Open a terminal window. By default, you will be in your home directory.
cd Desktop
ls
cat "filename"
Example
cd Desktop
ls
cat file1.txt
Related videos on Youtube
Pastey
Updated on September 18, 2022Comments
-
Pastey over 1 year
My goal is to open and the read the contents of a file that is located on my desktop using only the terminal to do so. My file has a space (" ") in its name, this has become troublesome because, cat seems to try to read 2 different files due to the space.
-
Jacob Vlijm over 9 yearsIt's not really clear to me, you want to save your files, but where does reading a text file on the desktop using terminal get on stage?
-
Alvar over 9 yearsDo you want to backup your data? Or open a file from the terminal? Or downgrade to 12.04? or fix your 14.04 version? Because your question is very confusing at the moment....
-
Flimm over 9 yearsThere is no Ubuntu 12, only Ubuntu 12.04 or Ubuntu 12.10. Similarly for Ubuntu 14.04 and Ubuntu 14.10.
-
Kaz Wolfe over 9 years
cat /path/to/file/name
-
Pastey over 9 years@Jacob Vlijm I've tried my best to clarify my question, FuzzyToothpaste has provided me with almost all the info i need, I'm still stumped by the space in my files name.
-
-
Paul over 9 yearsActually,
nano
is my first choice, but a user completely unfamiliar with cli may find it a little confusing, so I figured if the printing on the screen created a problem, then they would come back and ask about that. -
Pastey over 9 yearsIs there any command to search the directory for files or how many there are? I'm having trouble remembering the correct file names, they might not even be there.
-
John Scott over 9 yearsYeah. You use the ls command to list all files in the directory, with the exception of files that start with a period. If you think you might have one that does for whatever reason, run ls -a.
-
Pastey over 9 yearsThis is really helpful, ls -a seems to have found each directory under home, even files with periods. How do I view the contents of a specific folder, such as my desktop?
-
John Scott over 9 years@Pastey You will need to use the unrelated cd command. It is short for change directory. It lets you enter a folder. Your desktop is just a folder, you typing "cd Desktop" (without quotes) should do. If you get an error, try "cd ~/Desktop". The ~ represents your home directory. Then run ls or ls -a again.
-
Pastey over 9 yearsAlmost cracked this nut. My file has a space in its name and cat can't find the file properly with a space (er. file doesn't exist). I've tried a few symbols to represent the space but, I don't wanna edit or delete it by accident.
-
John Scott over 9 yearsThat is because space is a special character. If you do "cat your file", it will try to read a file called your and another file called file, which is not what you want. You can either put your filename in quotes like: cat "your file" or you can use a backwards slash () before the space. The slash tells it it's a special character. You then could do: cat your\ file.
-
nr5 almost 5 yearsWhat if I want to replace a string in another with the content of "filename"? I figured the replacement with
gsed
, but not sure how to put "filename" contents in a variable and use them: stackoverflow.com/q/56459572/1364053