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
    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
    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
    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
    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
    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

      Return to Full Article