Q&A for How to Find a File in Linux

Return to Full Article

Search
Add New Question
  • Question
    What does the 'ls' command do?
    Community Answer
    Community Answer
    The 'ls' command lists all files in the current directory you are working in. To find out what directory you are working in, type 'pwd' (stands for "print working directory").
  • Question
    Which command will display the last ten lines of a file?
    Community Answer
    Community Answer
    You have to used tail command to display the last lines of a file, the command used is, "tail -n filename." To display last 10 lines the command will be: tail -10 filename.
  • Question
    How can I find a file in the root directory if I've forgotten the name and the directory in which it was placed?
    Living Concrete
    Living Concrete
    Top Answerer
    You can try searching for a file extension, or checking places where files are commonly saved, such as your home directory. If it's a text file, you can try using a recursive grep search ('grep -R') with text that you remember from the file as search criteria.
  • Question
    My teacher wants me to use the command ls with ? to find certain files, but those file does'nt all have the same amount of charactere. How can I do?
    Nithik R
    Nithik R
    Community Answer
    Using `ls` you can find files that contain the specific letters you specify. For example, you want to find all files in the directory that contain "abc" in their name, type " ls -d *abc* " It will list all matching files. But if you want to find files more recursively, type " find | grep -r "abc" " You may remove the "-r" if you don't want to search too deep.
  • Question
    I want to search a file test.sh in home dir . If this file exists, then we need to print the path or else we need to create a same test.sh file and need to write "hello" in the created file. How can we do?
    Nithik R
    Nithik R
    Community Answer
    To find the file, type: `find ~/ -iname "test.sh" ` This will print the path to your file, if it exists. If you didn't find the file you are looking for, try searching in other places. To make a file and print hello, type this: ` touch test.sh ; echo "hello" > test.sh `
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit

Return to Full Article

You Might Also Like

Use Grep Use Grep to Search Text in Linux (Simple Examples)
Linux How to Find Large Files Find the Largest Files on Your Linux System
Rename Directory Linux Rename Linux Directory in Ubuntu, Fedora, & More
Use CygwinUsing Cygwin on Windows: Installing, Terminal Commands, & More
Open Applications Using Terminal on MacOpen Applications Using Terminal on Mac
Change File Permissions in Linux from the TerminalChange File Permissions in Linux from the Terminal
Tar a Directory Tar a Directory and Subdirectories in Linux
Check Logs in Unix Check Logs in Unix Systems
Create a File in a Directory in LinuxCreate a File in a Directory in Linux
Check Path in UnixCheck Path in Unix
Search on SlackSearch on Slack
Run Files in LinuxRun Files in Linux
Use MS DOS Use MS DOS
Linux How to SymlinkCreate Symbolic Links in Linux: Everything You Need to Know