Open file linux commands

Linux And Unix Command To View File

Linux And Unix Command To View File

Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux or Unix system
Est. reading time 2m
  • cat command
  • less command
  • more command
  • gnome-open command or xdg-open command (generic version) or kde-open command (kde version) – Linux gnome/kde desktop command to open any file.
  • open command – OS X specific command to open any file.

View a text file called foo.txt on a Linux or Unix-like systems

Open the Terminal application and type the following command to view a text file called foo.txt using cat command:
cat foo.txt
OR
cat /etc/resolv.conf
Sample outputs:

You can also use more or less command as follows:

gnome-open: Open files and directories/urls

The gnome-open command opens a file (or a directory or URL), just as if you had double-clicked the file’s icon. The syntax is:

If you are using KDE desktop try kde-open command as follows:

Another option is to try out xdg-open command on Linux and Unix desktop:

If you are using OS X Unix try open command as follows:

How do I list the files in a directory on Unix?

To see or list the files in a directory on Linux, run ls command:
ls
ls -l
If you would like to see and list files in another directory, use the ls along with the path to the directory:
ls /usr/
ls -l /etc/
## just list resolv.conf file #
ls -l /etc/resolv.conf

  • 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

Common ls command options

The syntax is:
ls [options] file
Where options for ls are:

  • -l : Use a long listing format to display Linux/Unix file names.
  • -a : Do not ignore entries starting with . (period). Display all hidden files.
  • -d : List Linux directories themselves, not their contents
  • -R : List sub-directories recursively on Linux
  • -F : Append indicator for file. For example, / for directories, * for executable Linux files, @ for symbolic links and more

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Sometimes the ‘ strings ‘ command is useful if the file is not all text. I seems to pull out text but leave the no text out.

Don’t forget: tac

Although I’ve yet to find a useful purpose for it

this sucks to high heaven,,linix is a pain in arse,,i dont know why anyone would use a fool system like this,,terminals suck,,i do mwean suck. terminals. idiots,,my windows got imploded,,i had to download this ubuntu,,i regret every god dam day of it,,i cant open any files,,cant open downloads or find them,,cant do anything on this. i dont know how or where to look,,terminal. /what the f is that,,how do you work it,,i checked on how to work this. just god dam crap,,you have to go to a college for hackers to know what all this shit is to work your browser,l. who ever made this for the common people. LIED,LIED. this is not for peopole,,its for hackers,,i tried to load windows on it,,it dont even let the software load,,i gues i9 have to delete this shit and then download,,this is shit,,i cant open a zip file,,i go to terminal and dont know what the fuck in doing in terminal. i check and forum say to put in different signalas or symbols i never seen before,,screw this and the dog it road in on. you ubuntu people are a bunch of crooks wanting to charge free for this. yes free is way to much money for this.

The cake is a lie.

The article on the other hand is great. Might use the addition of the most commonly used parameters.
Anyway, thanks. I was like “more” (mooar) 🙂 but forgot that you’re often satisfied with “less”

Hi
thanks a lot

Very useful and handy command to open and view files on Ubuntu desktop. thank you very much

Источник

How to open, create, edit, and view a file in Linux

One thing GNU/Linux does as well as any other operating system is give you the tools you need to create and edit text files. Ask ten Linux users to name their favorite text editor, and you might get ten different answers. On this page, we cover a few of the many text editors available for Linux.

GUI text editors

This section discusses text editing applications for the Linux windowing system, X Windows, more commonly known as X11 or X.

If you are coming from Microsoft Windows, you are no doubt familiar with the classic Windows text editor, Notepad. Linux offers many similar programs, including NEdit, gedit, and geany. Each of these programs are free software, and they each provide roughly the same functionality. It’s up to you to decide which one feels best and has the best interface for you. All three of these programs support syntax highlighting, which helps with editing source code or documents written in a markup language such as HTML or CSS.

NEdit

NEdit, which is short for the Nirvana Editor, is a straightforward text editor that is very similar to Notepad. It uses a Motif-style interface.

The NEdit homepage is located at https://sourceforge.net/projects/nedit/. If you are on a Debian or Ubuntu system, you can install NEdit with the following command:

For more information, see our NEdit information page.

Geany

Geany is a text editor that is a lot like Notepad++ for Windows. It provides a tabbed interface for working with multiple open files at once and has nifty features like displaying line numbers in the margin. It uses the GTK+ interface toolkit.

The Geany homepage is located at http://www.geany.org/. On Debian and Ubuntu systems, you can install Geany by running the command:

Gedit

Gedit is the default text editor of the GNOME desktop environment. It’s a great, text editor that can be used on about any Linux system.

The Gedit homepage is located at https://wiki.gnome.org/Apps/Gedit. On Debian and Ubuntu systems, Gedit can be installed by running the following command:

Terminal-based text editors

If you are working from the Linux command line interface and you need a text editor, you have many options. Here are some of the most popular:

pico started out as the editor built into the text-based e-mail program pine, and it was eventually packaged as a stand-alone program for editing text files. («pico» is a scientific prefix for very small things.)

The modern version of pine is called alpine, but pico is still called pico. You can find more information about how to use it in our pico command documentation.

On Debian and Ubuntu Linux systems, you can install pico using the command:

nano is the GNU version of pico and is essentially the same program under a different name.

On Debian and Ubuntu Linux systems, nano can be installed with the command:

vim, which stands for «vi improved,» is a text editor used by millions of computing professionals all over the world. Its controls are a little confusing at first, but once you get the hang of them, vim makes executing complex editing tasks fast and easy. For more information, see our in-depth vim guide.

On Debian and Ubuntu Linux systems, vim can be installed using the command:

emacs

emacs is a complex, highly customizable text editor with a built-in interpreter for the Lisp programming language. It is used religiously by some computer programmers, especially those who write computer programs in Lisp dialects such as Scheme. For more information, see our emacs information page.

On Debian and Ubuntu Linux systems, emacs can be installed using the command:

Redirecting command output into a text file

When at the Linux command line, you sometimes want to create or make changes to a text file without actually running a text editor. Here are some commands you might find useful.

Creating an empty file with the touch command

To create an empty file, it’s common to use the command touch. The touch command updates the atime and mtime attributes of a file as if the contents of the file had been changed — without actually changing anything. If you touch a file that doesn’t exist, the system creates the file without putting any data inside.

For instance, the command:

The above command creates a new, empty file called myfile.txt if that file does not already exist.

Redirecting text into a file

Sometimes you need to stick the output of a command into a file. To accomplish this quickly and easily, you can use the > symbol to redirect the output to a file.

For instance, the echo command is used to «echo» text as output. By default, this goes to the standard output — the screen. So the command:

The above command prints that text on your screen and return you to the command prompt. However, you can use > to redirect this output to a file. For instance:

The above command puts the text «Example text» into the file myfile.txt. If myfile.txt does not exist, it is created. If it already exists, its contents will be overwritten, destroying the previous contents and replacing them.

Be careful when redirecting output to a file using >. It will overwrite the previous contents of the file if it already exists. There is no undo for this operation, so make sure you want to completely replace the file’s contents before you run the command.

Here’s an example using another command:

The above command executes ls with the -l option, which gives a detailed list of files in the current directory. The > operator redirects the output to the file directory.txt, instead of printing it to the screen. If directory.txt does not exist, it is created first. If it already exists, its contents will be replaced.

Redirecting to the end of a file

The redirect operator >> is similar to >, but instead of overwriting the file contents, it appends the new data to the end of the file. For instance, the command:

Источник

Читайте также:  Скрипты python для windows администрирования
Оцените статью